在elasticsearch中使用模糊查询时找到实际匹配的单词
我是Elasticsearch的新手,正在寻找模糊查询搜索。
我用这样的对象/记录值制作了新的索引产品
{ "_index": "products",
"_type": "product",
"_id": "10",
"_score": 1,
"_source": {
"value": [
"Ipad",
"Apple",
"Air",
"32 GB"
]
}
}
现在当我在elasticsearch中执行模糊查询搜索时
{ query: {
fuzzy: {
value: "tpad"
}
}
}
它会向我返回预期的正确记录(上述产品)。
而且我知道该术语tpad
匹配,ipad
因此记录已归还。
但是从技术上讲,我怎么知道它已经匹配了ipad
。elasticsearch仅返回完整记录,像这样
{"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.61489093,
"hits": [
{
"_index": "products",
"_type": "product",
"_id": "10",
"_score": 0.61489093,
"_source": {
"value": [
"Ipad",
"Apple",
"Air",
"32 GB"
]
}
}
]
}
}
是否有elasticsearch任何方式,这样我可以知道,如果它匹配了tpad
反对ipad
回答:
如果使用高亮,Elasticsearch将显示匹配的术语:
curl -XGET http://localhost:9200/products/product/_search?pretty -d '{ "query" : {
"fuzzy" : {
"value" : "tpad"
}
},
"highlight": {
"fields" : {
"value" : {}
}
}
}'
Elasticsearch将返回匹配的文档,并突出显示该片段:
{ "took" : 31,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.13424811,
"hits" : [ {
"_index" : "products",
"_type" : "product",
"_id" : "10",
"_score" : 0.13424811,
"_source":{
"value" : ["Ipad",
"Apple",
"Air",
"32 GB"
]
},
"highlight" : {
"value" : [ "<em>Ipad</em>" ]
}
} ]
}
}
以上是 在elasticsearch中使用模糊查询时找到实际匹配的单词 的全部内容, 来源链接: utcz.com/qa/428215.html