Keyword field that is automatically appended to text field?


(David9) #1

We're relatively new to ES and discovered that after indexing some data, fields that are of type text now have a sub-field 'keyword' of type 'keyword'. Is this there to allow aggregation or other searches that are not allowed on text fields?

If so, and if we are starting our project from scratch, is it advisable to go this route so we can either do full text queries on the field, or keyword queries on the .keyword field...or should we make our field of type keyword to begin with? We are honestly not sure whether we will do stem-like queries on the field, so we'd like to be able to do either type of query. Thanks


(David Pilato) #2

Is this there to allow aggregation or other searches that are not allowed on text fields?

Yes. Aggs and Sorting most of the time.

Basically if you want to run full text search on a field where scoring is important for example, or using fuzzy queries, then use a text field.
If you need to compute aggs or do sorting, use keyword.

If you need to do both, do like elasticsearch is doing by default:

  • The field is a text type
  • The subfield *.keyword is a keyword type

(David9) #3

thanks! where is this documented? I can't find an explanation of that for 6.2


(David Pilato) #4

There: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/keyword.html


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.