-1

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

armzz_109
  • 45
  • 8
  • try using term query instead of match query – Amit May 30 '19 at 06:55
  • Hi Amit, The query is used is "es/_search?size=1000&from=0&q=account-validity&pretty=true" in browser. Where ti include 'term' query? Could you please explain? – armzz_109 May 30 '19 at 06:59
  • Instead of get method, you should make a post call to query, which gives you lot of flexibility .. this could be the cause of ur issue https://stackoverflow.com/questions/12195017/different-result-when-using-get-post-in-elastic-search – Amit May 30 '19 at 07:08
  • Also can you show the tokens generated for your documents using `_analyze` api – Amit May 30 '19 at 07:08

1 Answers1

0

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"
                }
            }
        }
    }
}'
armzz_109
  • 45
  • 8