弹性搜索中的查询字符串 [英] Query string in elastic search

查看:64
本文介绍了弹性搜索中的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的匹配查询来搜索弹性搜索,这没有给我确切的匹配,而是给了我更多的无关紧要的匹配.

Am searching elastic search with the below match query, which is not giving me the exact match instead its giving some more irrevalant match also.

am使用弹性搜索6.3

am using elastic search 6.3

请在下面找到我的查询

GET /_search
{
   "must":{
      "query_string":{
         "query":"review:*test product*"
      }
   }
}

搜索结果:

"hits":[{"_index":"67107104","_ type":"_ doc","_ id":"1","_ score":0.6931471,"_ source";:{"title":"testing"}},{"_index":"67107104","_ type":"_ doc","_ id":"2","_ score":0.6931471,"_ source":{"title";:产品好";}},{"_index":"67107104","_ type":"_ doc","_ id":"3","_ score":0.6931471,"_ source":{"title";:样本"}},{"_index":"67107104","_ type":"_ doc","_ id":"4","_ score":0.7897571,"_ source":{"title";:"superr"}}]

"hits": [ { "_index": "67107104", "_type": "_doc", "_id": "1", "_score": 0.6931471, "_source": { "title": "testing" } }, { "_index": "67107104", "_type": "_doc", "_id": "2", "_score": 0.6931471, "_source": { "title": "product good" } }, { "_index": "67107104", "_type": "_doc", "_id": "3", "_score": 0.6931471, "_source": { "title": "sample" } },{ "_index": "67107104", "_type": "_doc", "_id": "4", "_score": 0.7897571, "_source": { "title": "superr" } } ]

预期的搜索结果:

"hits":[{"_index":"67107104","_ type":"_ doc","_ id":"1","_ score":0.6931471,"_ source";:{"title":"testing"}},{"_index":"67107104","_ type":"_ doc","_ id":"2","_ score":0.6931471,"_ source":{"title";:产品好";}}]

"hits": [ { "_index": "67107104", "_type": "_doc", "_id": "1", "_score": 0.6931471, "_source": { "title": "testing" } }, { "_index": "67107104", "_type": "_doc", "_id": "2", "_score": 0.6931471, "_source": { "title": "product good" } } ]

推荐答案

如果尚未显式定义任何映射,则需要将.keyword添加到 title 字段.这将使用关键字分析器而不是标准分析器(请注意标题字段后的".keyword").

If you have not explicitly defined any mapping then you need to add .keyword to the title field. This uses the keyword analyzer instead of the standard analyzer (notice the ".keyword" after title field).

添加包含索引数据,搜索查询和搜索结果的工作示例

Adding a working example with index data, search query and search result

索引数据:

{
  "title": "This is test product"
}
{
  "title": "test product"
}

搜索查询:

{
  "query": {
    "query_string": {
      "fields": [
        "title.keyword"
      ],
      "query": "test product"
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "67107104",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.6931471,
        "_source": {
          "title": "test product"
        }
      }
    ]


使用匹配查询的搜索查询:

{
  "query": {
    "match": {
      "title.keyword": "test product"
    }
  }
}


使用词条查询的搜索查询

    {
      "query": {
        "term": {
          "title.keyword": "test product"
        }
      }
    }

这篇关于弹性搜索中的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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