liveBook · Manning

Fielddata

As explained in Elasticsearch in Action, Second Edition

Fielddata is Elasticsearch’s on-heap data structure for loading text-field values to support operations such as sorting and aggregations.

When a student age is indexed as text, Elasticsearch blocks sorting by default. Fielddata enables text-field values to support sorting and aggregations. section 4.2.2 section 13.2.2

Set "fielddata": true in the field mapping to load per-document text values. Elasticsearch stores this data in the cluster’s on-heap fielddata cache, so enabling it can consume substantial memory and reduce performance. section 4.2.2 section 13.2.2

Enable fielddata on a text field

PUT students_with_fielddata_setting { "mappings": { "properties": { "age": { "type": "text", "fielddata": true } } } } This mapping permits operations such as sorting on age, but age.keyword is generally preferred when Elasticsearch creates that keyword multi-field. Sorting on age.keyword avoids enabling fielddata for the text field. section 4.2.2

Choose fielddata deliberately:

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines the mapping switch, explains heap costs, and compares keyword fields, but does not detail fielddata internals.
Examples
Uses student ages for sorting and television-sales names for aggregation examples.
What it assumes
Assumes familiarity with Elasticsearch mappings, text fields, keyword fields, sorting, and aggregations.
What you can do after
Operate/configure Elasticsearch mappings to enable text-field sorting or aggregations while assessing heap-memory tradeoffs.
How it connects
Connects text fields with sorting, aggregations, keyword fields, multi-fields, and dynamic mapping.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.