我有以下格式的彈性檔案,其中主干值可以是[1PCX05, 2PCX05, 3PCX05 6PCX05] 之一
"doc": {
"keys": {
"trunk": "6PCX05",
"direction": "incoming",
"country": "CHN",
"service": "ENTVTS",
"company": "XYZ"
}
}
但是,當我運行以下查詢以過濾有關過濾公司欄位和 must_not -> 具有特定中繼但 must_not cluase 的術語的檔案時,我正在獲取公司名稱為“XYZ”的所有檔案
POST /my_index-*/_search
{
"query": {
"bool": {
"filter": [
{
"match": {
"doc.keys.company": {
"query": "XYZ",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
}
],
"must_not": [
{
"terms": {
"doc.keys.trunk": [
"3PCX05,2PCX05,1PCX05"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
我也嘗試在 doc.keys.trunk.keyword 中使用關鍵字,但仍然無法正常作業
uj5u.com熱心網友回復:
TLDR;
你確定.keyword不作業?對我來說,很明顯這是解決問題的方法。
重現
我創建了一個玩具專案來嘗試模擬您的情況。
# Truck 1
POST /71188384/_doc
{
"doc": {
"keys": {
"trunk": "6PCX05",
"direction": "incoming",
"country": "CHN",
"service": "ENTVTS",
"company": "XYZ"
}
}
}
# Truck 2
POST /71188384/_doc
{
"doc": {
"keys": {
"trunk": "6PCX06",
"direction": "incoming",
"country": "CHN",
"service": "ENTVTS",
"company": "XYZ"
}
}
}
GET /71188384/_search
{
"query": {
"bool": {
"filter": [
{
"match": {
"doc.keys.company": {
"query": "XYZ",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
}
],
"must_not": [
{
"terms": {
"doc.keys.trunk.keyword": ["6PCX05"],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
我確實成功了Truck 2
{
...
"_source" : {
"doc" : {
"keys" : {
"trunk" : "6PCX06",
"direction" : "incoming",
"country" : "CHN",
"service" : "ENTVTS",
"company" : "XYZ"
}
}
}
...
}
這是我的映射:
{
"71188384" : {
"aliases" : { },
"mappings" : {
"properties" : {
"doc" : {
"properties" : {
"keys" : {
"properties" : {
"company" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"country" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"direction" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"service" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"trunk" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
},
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "71188384",
"creation_date" : "1645309336806",
"number_of_replicas" : "1",
"uuid" : "5vw9ZKmYQ1aWh_Rs0ajckg",
"version" : {
"created" : "7160399"
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428927.html
