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

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

问题描述

假设我们有数据: -




  { _id:1,name:Doeman John} 
{_id:2,name:John}
pre>


使用查询: -




  {

查询:{
query_string:{
fields:[name],
query:John
}
}
}




实际结果: -




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




预期结果: -




 code> {_ id:2,name:John} 

我正在使用标准分析仪。

解决方案

可以实现我的预期结果您不能在不更改分析器设置的情况下实现此目的。
如果您还想使用标准分析器,您可以使您的字段 multifield

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

,然后在 not_analyzed 版本上运行您的查询。

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

这将根据您的要求提取结果。



`


Suppose We have data :-

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

Query Used :-

{ 

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

Actual result :-

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

Expected result :-

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

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

解决方案

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

and then run your query on the not_analyzed version.

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

This will fetch results as per your requirement.

`

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

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