我有我似乎忽略了「must_not」部分(使用感測試/調試)的elasticsearch查詢彈性搜索must_not越來越忽略
POST /myserver.dev/indexedproduct/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"isPublished": true
}
},
{
"term": {
"isProjectPublished": true
}
},
{
"term": {
"hidden": false
}
},
{
"bool": {
"must_not": [
{
"term": {
"excludedMarkets": ["GI"]
}
}
]
}
},
{
"bool": {
"should": [
{
"terms": {
"category": [
"headwear"
]
}
}
]
}
}
]
}
}
}
}
}
這是返回104個結果。
如果我運行:
POST /myserver.dev/indexedproduct/_search
{
"query": {
"bool": {
"must_not": { "match": { "excludedMarkets": "GI"}}
}
}
}
那麼這將返回41個結果。
由於「must_not」子句,我期望第一個(不工作的)返回41個或更少的結果。
我已經看過ES文檔,並且我的查詢看起來在過濾查詢和嵌套must/must_not語句方面看起來是正確的。
任何幫助,將不勝感激。
編輯,測試數據,僅2,一個與GI exludedMarkerts,一個沒有,這意味着最終的結果應該返回只有一個,
"_index":"myindex.dev",
"_type":"indexedproduct",
"_id":"29426",
"_score":1,
"_source":{
"id":29426,
"sku":"0123",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ne.",
"searchKeywords":[
"Lorem",
"ipsum",
"dolor"
],
"productType":[
"Ipsum"
],
"category":[
"Lorem"
],
"colour":[
"Black/Black"
],
"prices":{
"eur":35,
"gbp":28
},
"catalogId":3,
"ageRange":[
"adults"
],
"brand":[
null
],
"available":true,
"bestSeller":false,
"collections":[
"lorumipsum"
],
"fit":[
"fitted"
],
"newArrival":false,
"style":[
"Lorum"
],
"excludedMarkets":[
"BA",
"GI",
"MC",
"MD",
"SM",
"AL"
],
"isPublished":true,
"isTranslated":false,
"isProjectPublished":true,
"hidden":false,
"availableDate":"2015-09-17T01:00:00+01:00"
}
},
"_index":"myindex.dev",
"_type":"indexedproduct",
"_id":"2942",
"_score":1,
"_source":{
"id":2942,
"sku":"012",
"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ne.",
"searchKeywords":[
"Lorem",
"ipsum",
"dolor"
],
"productType":[
"IpsumLorem"
],
"category":[
"IpsumLorem"
],
"colour":[
"Black/Blue"
],
"prices":{
"eur":35,
"gbp":28
},
"catalogId":3,
"ageRange":[
"adults"
],
"brand":[
null
],
"available":true,
"bestSeller":false,
"collections":[
"lorumipsum"
],
"fit":[
"fitted"
],
"newArrival":false,
"style":[
"Lorum"
],
"excludedMarkets":[
"BA",
"MC",
"MD",
"SM",
"AL"
],
"isPublished":true,
"isTranslated":false,
"isProjectPublished":true,
"hidden":false,
"availableDate":"2015-09-17T01:00:00+01:00"
}
}
你好,感謝,仍然帶回很多(104點擊)。也許我需要查詢,然後再次查詢,所以must_not超出了過濾 – jaymarvels
@ jj72uk也許你應該在'must_not'子句中使用'terms'而不是'term'? –
我也曾嘗試過,發帖之前:) – jaymarvels