我有以下 Elasticsearch 查询,返回大量结果。
{
"query": {
"multi_match": {
"query": "swartz",
"fields": ["notes"]
}
},
"size": 20,
"from": 0,
"sort": {
"last_modified_date": {
"order": "desc"
}
}
}
我正在尝试将其重做为 bool(boolean) 查询,以便可以添加should和must_not,但是没有任何结果,我不确定为什么。{
"query": {
"bool": {
"must": [
{"term": { "notes": "swartz" }}
]
}
},
"size": 20,
"from": 0,
"sort": {
"last_modified_date": {
"order": "desc"
}
}
}
我得到的不是结果,而是结果。 "took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 6,
"successful" : 5,
"skipped" : 0,
"failed" : 1,
"failures" : [
{
"shard" : 0,
"index" : ".kibana_1",
"node" : "E2fjoon_Smm5m7LFcQp9XQ",
"reason" : {
"type" : "query_shard_exception",
"reason" : "No mapping found for [last_modified_date] in order to sort on",
"index_uuid" : "0pZdhm_nRXWiWGcqFgvvHQ",
"index" : ".kibana_1"
}
}
]
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
首先,我不确定为什么会得到结果,并且它对第一个查询的排序正确,其次,即使我从第二个查询中删除了排序,也仍然没有结果。
最佳答案
首先,您使用匹配查询将在“注释”内容中的某个位置查找任何出现的“swartz”。
在SQL世界中,它类似于:
where notes ilike "%swartz%"
在第二个查询中,您将使用术语查询,该查询将在字段中寻找完美的相等性。在SQL中:
where "notes"=="swartz"
它可能可以解释你的行为https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
关于elasticsearch - 这些elasticsearch查询有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63513092/