在弹性搜索中使用模糊查询时查找实际匹配词 [英] Find actual matching word when using fuzzy query in elastic search

查看:168
本文介绍了在弹性搜索中使用模糊查询时查找实际匹配词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是弹性搜索的新手,正在查看模糊查询搜索。

我已经创建了一个新的索引产品,具有这样的对象/记录值。

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 http://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>" ]
      }
    } ]
  }
}

这篇关于在弹性搜索中使用模糊查询时查找实际匹配词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆