elasticsearch 弹性搜索不能被忽略,elasticsearch,elasticsearch" /> elasticsearch 弹性搜索不能被忽略,elasticsearch,elasticsearch" />

elasticsearch 弹性搜索不能被忽略

elasticsearch 弹性搜索不能被忽略,elasticsearch,elasticsearch,我有一个elasticsearch查询,在我看来,它似乎忽略了“不得”部分(使用sense进行测试/调试) 这将返回104个结果 如果我跑步: POST /myserver.dev/indexedproduct/_search { "query": { "bool": { "must_not": { "match": { "excludedMarkets": "GI"}} } } } 然后返回41个结果 由于“mu

我有一个elasticsearch查询,在我看来,它似乎忽略了“不得”部分(使用sense进行测试/调试)

这将返回104个结果

如果我跑步:

POST /myserver.dev/indexedproduct/_search
{
    "query": { 
        "bool": {
            "must_not": { "match": { "excludedMarkets":   "GI"}}
        }
    }
} 
然后返回41个结果

由于“must_not”子句,我希望第一个(不起作用的)返回41个或更少的结果

我已经看过ES文档,我的查询在过滤查询和嵌套的must/must\u not语句方面的格式正确

任何帮助都将不胜感激

编辑,测试数据,只有2个,一个有GI排除标记,一个没有,这意味着最终结果应该只返回一个

"_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"
}
}

您应该有
必须
/
不得
应该
子句处于同一级别。此查询应适用于以下情况:

POST /myserver.dev/indexedproduct/_search
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            { "term": { "isPublished": true } },
            { "term": { "isProjectPublished": true } },
            { "term": { "hidden": false } }
          ],
          "must_not": [
            { "term": { "excludedMarkets": ["GI"] } }
          ],
          "should": [
            { "terms": { "category": ["headwear"] } }
          ]
        }
      }
    }
  }
}

我希望这能奏效:试试这个

    POST /myserver.dev/indexedproduct/_search
    {
        "query": {
         "filtered": {
           "filter": {
            "bool": {
              "must": [{"term": {"isPublished": true}},
                       {"term": {"isProjectPublished": true}},
                       {"term": {"hidden": false}},
                       {"bool": {
                          "must_not": [{"terms": {"excludedMarkets": ["GI"]}}]
                         }
                    },
                    {"bool": { "should": [{"terms": {"category": ["headwear"]}}]}}
             ]
            }
          }
        }
      }
    }

我使用的是elasticsearch 2.1,当我使用term而不是terms时,它会给我提供查询_解析_异常。

您好,谢谢您,仍然有很多(104次点击)。也许我需要一次又一次地查询,所以必须在filtered@jj72uk也许你应该在
不得
子句中使用
术语
而不是
术语
?我在发布之前也尝试过:)@jj72uk你能给你的问题添加一些测试数据吗?将更容易解决。@jj72uk看起来像是
should
过滤器在这里充当
must
的角色。你可能需要以固定分数的查询方式运行它。这仍然会在@jj72uk上带来104个点击率。你能编辑你的帖子并给出一个例子或数据样本吗?
    POST /myserver.dev/indexedproduct/_search
    {
        "query": {
         "filtered": {
           "filter": {
            "bool": {
              "must": [{"term": {"isPublished": true}},
                       {"term": {"isProjectPublished": true}},
                       {"term": {"hidden": false}},
                       {"bool": {
                          "must_not": [{"terms": {"excludedMarkets": ["GI"]}}]
                         }
                    },
                    {"bool": { "should": [{"terms": {"category": ["headwear"]}}]}}
             ]
            }
          }
        }
      }
    }