简体   繁体   English

如何从弹性搜索查询中获得准确的搜索结果

[英]how to get exact search result from elastic search query

I need the exact match result from elastic search query我需要来自弹性搜索查询的精确匹配结果

I tried keeping index as "not analysed" while indexing using this curl command:我尝试在使用此 curl 命令建立索引时将索引保持为“未分析”:

curl -X PUT es/_doc/all -H'Content-Type: application/json' -d '{
  "mappings": {
    "dynamic_templates": [
      {
        "example_string_as_object": {
          "match_mapping_type": "object",
          "match":   "x-example",
          "mapping": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    ]
  }
  }'

But still, when I try a query with "account-validity", I am getting the result of both 'account' and 'validity'.但是,当我尝试使用“account-validity”进行查询时,我得到了“account”和“validity”的结果。

I need the result showing document that only have "account-validity".我需要显示仅具有“帐户有效性”的文档的结果。 The query I am using:我正在使用的查询:

es/_search?size=1000&from=0&q=account-validity&pretty=true es/_search?size=1000&from=0&q=account-validity&pretty=true

can someone please help me with this有人可以帮我解决这个问题吗

I was able to solve this by using the parameter "term" before the data which I need exact search for.我能够通过在需要精确搜索的数据之前使用参数“term”来解决这个问题。

PFB an example which shows the exact match for name = ABC PFB 一个示例,它显示了 name = ABC 的完全匹配

{
    "query" : {
        "constant_score" : {
            "filter" : {
                "term" : {
                    "Name" : "ABC"
                }
            }
        }
    }
}'

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

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