简体   繁体   中英

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 -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'.

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

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.

PFB an example which shows the exact match for name = ABC

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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