Keyword field that is automatically appended to text field?

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

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

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

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

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