简体   繁体   English

弹性搜索 REST 查询返回超出预期

[英]Elastic search REST query returning more than expected

In order to search for the exact string: "AGA>23/180@20210212" I've tried the below match queries:为了搜索确切的字符串: "AGA>23/180@20210212"我尝试了以下match查询:

{"query": { "match" : {"mid": "AGA>23/180@20210212"}}}
{"query": {"bool": { "must" : [ { "match" : { "mid": "AGA>23/180@23221"}}]}}}

elastic search matches on "AGA>135/880@20210212" & "AGA>212/880@20210212"弹性搜索匹配"AGA>135/880@20210212""AGA>212/880@20210212"

So it seems the values 135 & 212 are treated like wildcards.因此,值135212似乎被视为通配符。

If I use query instead: {"query": { "term": {"mid": "AGA>23/180@20210212"}}} then 0 results are returned.如果我改用query{"query": { "term": {"mid": "AGA>23/180@20210212"}}}则返回 0 个结果。

How to search for value "AGA>23/180@20210212" only?如何仅搜索值"AGA>23/180@20210212"

The term query returns documents that contain an exact term in a provided field. 术语查询返回在提供的字段中包含确切术语的文档。

By default standard analyzer is used.默认情况下使用标准分析器 It will provide grammar based tokenization for AGA>23/180@20210212 and will generate the following tokens.它将为AGA>23/180@20210212提供基于语法的标记化,并将生成以下标记。

aga , 23 , 180 , 20210212 aga , 23 , 180 , 20210212

Due to this, the match query matches on "AGA>135/880@20210212" & "AGA>212/880@20210212"因此,匹配查询匹配"AGA>135/880@20210212""AGA>212/880@20210212"

To search for the exact term you need to add.keyword to the mid field (if you have not explicitly defined any mapping for the field).要搜索确切的术语,您需要将.keyword 添加到mid字段(如果您没有明确定义该字段的任何映射)。 This uses the keyword analyzer instead of the standard analyzer (notice the ".keyword" after mid field).这使用关键字分析器而不是标准分析器(注意mid字段后的“.keyword”)。 Try out this below query -试试下面的查询 -

{
  "query": {
    "term": {
      "mid.keyword": "AGA>23/180@20210212"
    }
  }
}

OR you can change your index mapping to或者您可以将索引映射更改为

{
  "mappings": {
    "properties": {
      "mid": {
        "type": "keyword"
      }
    }
  }
}

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

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