首先,有一个"bool"
查询和一个"bool"
过滤器,他们去了不同的地方,做了些微不同的事情。作为一般规则,如果你可以使用一个过滤器来做(它们中的许多可以被缓存,并且即使不是更快一点)。如果您需要"match"
,那么您需要查询。
你引用实际上可以用任何一种方式在页面上的例子:
作为查询:
POST /test_index/_search
{
"query": {
"bool": {
"must": {
"term": {
"user": "kimchy"
}
},
"must_not": {
"range": {
"age": {
"from": 10,
"to": 20
}
}
},
"should": [
{
"term": {
"tag": "wow"
}
},
{
"term": {
"tag": "elasticsearch"
}
}
],
"minimum_should_match": 1,
"boost": 1
}
}
}
或过滤器(在filtered query):
POST /test_index/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"term": {
"user": "kimchy"
}
},
"must_not": {
"range": {
"age": {
"from": 10,
"to": 20
}
}
},
"should": [
{
"term": {
"tag": "wow"
}
},
{
"term": {
"tag": "elasticsearch"
}
}
],
"minimum_should_match": 1
}
}
}
}
}
另外,我完全对ES文件感到沮丧。我已经和他们一起工作了几年,现在看起来他们似乎并没有好转。也许负责文档的人员并不在乎。阴谋论认为,糟糕的文档可以帮助公司销售专业服务。
是的,我希望公司改善文档或失败惨败。我只想看到两种选择,很抱歉说。 –
其实我还没有看到它,但它看起来像他们在2.0中改变了事情。看起来你不再需要过滤的查询,只是布尔查询:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html –