简体   繁体   English

弹性搜索默认情况下不考虑作为字符串字段,并且未给出正确的匹配结果

[英]Elastic search not considering as string field by default and not giving proper matching results

I am querying ElasticSearch by using the following query and it is giving me results as per the query along with some other irrelevant data. 我正在通过使用以下查询来查询ElasticSearch,它为我提供了根据该查询获得的结果以及一些其他不相关的数据。

GET items/_search
{
  "query" :{
      "match": {"code": "*7000-8002-W*"}
  }
}

But if I query like this, I am getting the proper results: 但是,如果我这样查询,我将得到正确的结果:

GET items/_search
{
  "query" :{
      "match": {"code": "*S6617523*"}
  }
}

Why is the first query returns some other irrelevant data? 为什么第一个查询返回其他一些不相关的数据?

This behaviour is due to the way ES analyzes the string. 此行为归因于ES分析字符串的方式。 In this case you need to apply wildcard query on raw field of code like 在这种情况下,您需要对类似code原始字段应用wildcard查询

{ 
"query": { 
 "wildcard": { 
  "code.keyword": { 
  "value": "*7000-6000*" 
    } 
   } 
  } 
 }

Java API orresponding to this will be 对此的Java API将会是

QueryBuilders.wildcardQuery("code.keyword","*7000-6000*");

Hope this Helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM