Query_string搜索无法正常工作 [英] Query_string search is not working as expected

查看:54
本文介绍了Query_string搜索无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有这样的数据:

Suppose we have data like this:

{ "_id" : "1","name" : "Doeman John"}
{"_id" : "2","name" : "John"}

使用的查询:

{ 
  "query": {
    "query_string": {
       "fields" : ["name"] ,
      "query": "John"
    }
  }
}

当前结果:

{ "_id" : "1","name" : "Doeman John"}
{"_id" : "2","name" : "John"}

预期结果:

{"_id" : "2","name" : "John"}

我正在使用标准分析仪.我可以在不更改任何分析器设置的情况下达到我的预期结果吗?

I am using Standard Analyzer. Could I achieve my expected result without changing any Analyzer setting?

推荐答案

如果不更改 analyzer 设置,将无法实现此目的.如果您仍然想使用 Standard Analyzer ,则可以将字段设置为 multifield .

You can not achieve this without changing analyzer settings. In case you still want to use Standard Analyzer, you can make your field multifield.

 {
 "mappings": {
 "my_type": {
  "properties": {
    "name": {
      "type": "text",
      "fields": {
        "raw": { 
          "type":  "keyword"
          }
        }
      } 
     }
  }
 }
}

,然后在 not_analyzed 版本上运行查询.

and then run your query on the not_analyzed version.

  {
   "query": {
   "term": {
   "name.raw": {
      "value": "John"
      }
    }
   }
  }

这将根据您的要求获取结果.

This will fetch results as per your requirement.

`

这篇关于Query_string搜索无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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