我正在使用Elasticsearch 6.8。我的索引中有一个文档,如下所示:
$ curl "http://localhost:9200/users/_search"|jq
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "users",
"_type": "1",
"_id": "WzLeNG4BVtGh82ZM-BBl",
"_score": 1,
"_source": {
"name": "joey",
"description": "xpxpxp all xpxpxp"
}
}
]
}
}
如果我在下面的查询中使用它,确实会向我返回文档。
{
"query": {
"bool": {
"filter": {
"term": {
"name": "joey"
}
},
"should": [
{
"constant_score": {
"filter": {
"match_phrase": {
"description": "xpxpxp dd All xpxpxp"
}
}
}
}
]
}
}
}
但是如果我使用下面的查询,它什么也不会返回:
{
"query": {
"bool": {
"should": [
{
"constant_score": {
"filter": {
"match_phrase": {
"description": "xpxpxp dd All xpxpxp"
}
}
}
}
]
}
}
}
这两个查询请求之间的区别在于,第一个查询请求在
filter
之前具有should
。我不知道为什么这会更改should
行为?
最佳答案
您的should子句不匹配,因为match_phrase
字段上的description
无法匹配xpxpxp dd All xpxpxp
,因为该字段包含xpxpxp all xpxpxp
第一个查询返回文档,因为name
字段匹配joey
。
关于elasticsearch - 在Elasticsearch中 `should`之后 `filter`如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58687739/