liveBook · Manning

Multi-typed field

As explained in Elasticsearch in Action, Second Edition

A multi-field is an Elasticsearch mapping definition that indexes one field value in multiple ways under separate subfields.

A multi-typed field indexes one value in multiple ways under separate subfields. A book title can remain a text field for full-text search while also exposing title.raw as a keyword field for exact-value searches. section 15.1.3 section 4.1.2

The main field is analyzed and tokenized for full-text queries. Its keyword subfield is kept as one exact value, avoiding analysis when exact matching or other keyword operations are appropriate. section 4.1.2 section 15.1.3

Search a title exactly

Define both representations, then query the keyword subfield with the exact indexed spelling: PUT programming_books3 { "mappings": { "properties": { "title": { "type": "text", "fields": { "raw": { "type": "keyword" } } } } } } PUT programming_books3/_doc/1 { "title": "Elasticsearch in Action" } GET programming_books3/_search { "query": { "match": { "title.raw": "Elasticsearch in Action" } } } Use title for analyzed full-text search and title.raw for an exact keyword search. A spelling or capitalization difference produces no keyword match.

Dynamic mapping commonly creates a keyword subfield automatically, such as age.keyword. Sorting on that subfield works, whereas sorting directly on a text field fails by default. section 4.2.2

Choose the additional field according to the operation:

  • Use a keyword subfield for exact values, sorting, filtering, or aggregations when the value should not undergo text analysis. section 4.2.2 section 4.1.2
  • Use fielddata on text only as an override; it is stored in heap memory and can cause expensive computations and cluster performance issues. section 4.2.2
  • Use another multi-field such as title.word_count when a structured value derived from analyzed text must be queried. section 4.5.1

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains mapping, analysis behavior, queries, sorting, and fielddata trade-offs, while deferring broader data types and advanced descendants.
Examples
Demonstrates movie titles, programming-book titles, student ages, exact title queries, ascending sorts, and title word-count queries.
What you can do after
Apply it via Elasticsearch mappings and REST queries to preserve full-text search while enabling exact-value operations on subfields.
How it connects
Connects dynamic mapping, text fields, keyword fields, text analysis, exact matching, sorting, aggregations, filtering, and token_count.

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.