我正在使用 fuzzy
并希望 elasticsearch 返回搜索到的单词而不仅仅是命中。
当我搜索 dogo
这个词时我的模糊搜索找到了这个词 dog
我想知道它是 dogo
谁发现了它。
数据:
{ "index": { "_id":1 }}
{ "title": "The quick brown fox", "price":5 }
{ "index": { "_id":2 }}
{ "title": "The quick blue dog", "price":7 }
{ "index": { "_id":3 }}
{ "title": "The slow brown dog", "price":5 }
查询:
{
"query": {
"bool": {
"should": [
{
"fuzzy": {
"title": "dogo"
}
},
{
"fuzzy": {
"title": "fox"
}
}
]
}
},
"highlight" : {
"fields" : {
"title":{
"pre_tags": [
"===>"
],
"post_tags": [
"<==="
],
"fragment_size": 200,
"number_of_fragments": 100
}
}
}
}
此查询将返回 ===>dog<===
但不知道是否dogo
找到了。
有谁知道怎么做或有什么想法吗?
我希望我的输出类似于 dog : dogo
.
最佳答案
你可以使用 named queries为此,通过为每个查询命名。在结果中,每个命中都将包含一个 matched_queries
数组,其中包含匹配的查询的名称(例如下面的 dogo
和 fox
)。
{
"query": {
"bool": {
"should": [
{
"fuzzy": {
"name": {
"value": "dogo",
"_name": "dogo"
}
}
},
{
"fuzzy": {
"name": {
"value": "fox",
"_name": "fox"
}
}
}
]
}
},
"highlight": {
"fields": {
"title": {
"pre_tags": [
"===>"
],
"post_tags": [
"<==="
],
"fragment_size": 200,
"number_of_fragments": 100
}
}
}
}
关于python - Elasticsearch 返回搜索到的词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59361024/