Home > Software engineering >  Elasticsearch query match one word
Elasticsearch query match one word

Time:11-11

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"
   }
  }
 }
}

CodePudding user response:

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

  • Related