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
