skynyrd
3/7/2017 - 7:41 PM

Keyword vs Text in Elastic 5

Keyword vs Text in Elastic 5

Text fields:

  • Analyzed
  • Elastic search seperate or tokenize each word, remove punctuations, convert to lowercase and etc.

Keyword fields:

  • Exact match.

Term Queries are fit to keywords, numeric fields or dates, instead of full text. For full text, match query is far better option.


Let's assume that we have a full field, that is text and exact field that is keyword.

After we push a doc:

PUT /example_index/type
{
  "full" : "Hello, World!",
  "exact" : "Hello, World!"
}

This query returns 1 as exact is keyword and stored as "Hello, World!" and term query looks for exact match:

GET /example_index/type/_count
{
  "query" : {
    "term" : {
      "exact" : "Hello, World!"
    }
  }
}

This query returns 0 as full is text and stored as "hello,world" and term query looks for exact match:

GET /example_index/type/_count
{
  "query" : {
    "term" : {
      "full" : "Hello, World!"
    }
  }
}

This query returns 1 as full is text and stored as "hello,world" and match query handles that:

GET /example_index/type/_count
{
  "query" : {
    "match" : {
      "full" : "Hello, World!"
    }
  }
}