elasticsearch 在弹性搜索中使用模糊查询查找实际匹配词
我是elasticsearch的新手,一直在寻找模糊查询搜索。
elasticsearch 在弹性搜索中使用模糊查询查找实际匹配词,
elasticsearch,lucene,fuzzy-search,
elasticsearch,Lucene,Fuzzy Search,我是elasticsearch的新手,一直在寻找模糊查询搜索。 我制作了一个新的索引产品,其对象/记录值如下 { "_index": "products", "_type": "product", "_id": "10", "_score": 1, "_source": { "value": [ "Ipad
我制作了一个新的索引产品,其对象/记录值如下
{
"_index": "products",
"_type": "product",
"_id": "10",
"_score": 1,
"_source": {
"value": [
"Ipad",
"Apple",
"Air",
"32 GB"
]
}
}
现在,当我在elasticsearch中执行模糊查询搜索时
{
query: {
fuzzy: {
value: "tpad"
}
}
}
它会返回我期望的正确记录(上面刚刚制作的产品)。我知道术语
tpad
与ipad
匹配,所以记录是返回的。但从技术上讲,我怎么知道它与ipad相配呢。弹性搜索只返回完整的记录,如下所示
{
"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"
]
}
}
]
}
}
elastic search中是否有任何方法可以让我知道它是否已将tpad
与ipad
匹配。如果使用,elastic search将显示匹配的术语:
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>" ]
}
} ]
}
}
{
“take”:31,
“超时”:false,
“_碎片”:{
“总数”:5,
“成功”:5,
“失败”:0
},
“点击次数”:{
“总数”:1,
“最高分数”:0.13424811,
“点击次数”:[{
“_索引”:“产品”,
“_类型”:“产品”,
“_id”:“10”,
“_分数”:0.13424811,
“_来源”:{
“价值”:[“Ipad”,
“苹果”,
“空气”,
“32 GB”
]
},
“亮点”:{
“价值”:[“Ipad”]
}
} ]
}
}
如果您只想分析结果,可以使用Inquisitor插件
如果您需要以编程方式执行此操作,我认为突出显示功能将帮助您:
我知道这个问题比较老,但我刚刚碰到了。我这样做的方式是在构建查询时填充查询名称字段。这样,它将返回到“matchedQuery”字段中作为响应。希望这有帮助:)有没有可能用另一种方法?我想知道“tpad”(来自我的查询字符串)是否匹配,而不是“ipad”(来自文档)是否匹配。@ankr您的查询得到答案了吗?我也在寻找一些不匹配单词的信息,但到目前为止,我没有找到任何东西。你能详细说明一下吗?谢谢