在弹性搜索中使用模糊查询时查找实际匹配词

编程入门 行业动态 更新时间:2024-10-10 10:25:47
本文介绍了在弹性搜索中使用模糊查询时查找实际匹配词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是弹性搜索的新手,正在查看模糊查询搜索。 我已经创建了一个新的索引产品,具有这样的对象/记录值。

I am new to elasticsearch and was looking around fuzzy query search. I have made a new index products with object/record values like this

{ "_index": "products", "_type": "product", "_id": "10", "_score": 1, "_source": { "value": [ "Ipad", "Apple", "Air", "32 GB" ] } }

现在当我在弹性搜索中执行模糊查询搜索,如

Now when i am performing a fuzzy query search in elasticsearch like

{ query: { fuzzy: { value: "tpad" } } }

它返回我正确的记录(上面的产品),这是预期的。 我知道这个术语 tpad 匹配 ipad 所以记录是返回。 但从技术上讲,我如何知道它已经匹配 ipad 。弹性搜索只返回这样的完整记录(或记录)

It returns me the correct record (the product just made above) which is expected. And i know that the term tpad matches ipad so record was return. But technically how would i know that it has matched ipad. Elastic search just returns the full record(or records) like this

{ "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" ] } } ] } }

有弹性搜索有什么办法,以便我可以知道它是否符合 tpad 对 ipad

Is there any way in elastic search so that i can know if it has matched tpad against ipad

推荐答案

如果您使用突出显示,Elasticsearch将显示匹配的条款:

if you use highlighting, Elasticsearch will show the terms that matched:

curl -XGET localhost:9200/products/product/_search?pretty -d '{ "query" : { "fuzzy" : { "value" : "tpad" } }, "highlight": { "fields" : { "value" : {} } } }'

Elasticsearch将返回匹配的文档,其中突出显示的片段:

Elasticsearch will return matching documents with the fragment highlighted:

{ "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>" ] } } ] } }

更多推荐

在弹性搜索中使用模糊查询时查找实际匹配词

本文发布于:2023-11-28 20:04:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹性   模糊

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!