Ismeet
Ismeet

Reputation: 449

Elasticsearch query match one word

if i have three rows like

name: "cat"
name: "cat is white"
name: "cat is black"

If i query filed name with string 'cat' using match or term query, get all three results.

How to get only name: "cat"?

GET animals/_search
{
 "query": {
   "match": {
     "name": {
      "query": "cat"
   }
  }
 }
}

Upvotes: 0

Views: 45

Answers (1)

jaspreet chahal
jaspreet chahal

Reputation: 9109

Use term query on keyword field

Returns documents that contain an exact term in a provided field.

GET /_search
{
  "query": {
    "term": {
      "name.keyword": {
        "value": "cat"
      }
    }
  }
}

term query performs case sensitive match. If you want case insensitive match you will have to use normalizer on keyword field

Upvotes: 1

Related Questions