liveBook · Manning

Fields object

As explained in Elasticsearch in Action, Second Edition

The fields object is a mapping configuration object that defines additional data-type representations for a field.

In an Elasticsearch movie or email mapping, the fields object gives one field additional data-type representations. A subject or title can remain text for full-text search while exposing keyword or completion forms for other operations. section 4.7

One value, several searchable forms

A subject mapped as text, keyword, and completion is still supplied as one field value. Query subject for analyzed text, subject.kw for exact matching, or subject.comp for completion behavior. The dot-separated names identify the additional field representations. section 4.7

Listing 4.43 Schema definition with a multi-typed field
PUT emails_multi_type
{
  "mappings": {
    "properties": {
      "subject":{
        "type": "text",                    #1
        "fields": {
          "kw":{ "type":"keyword" },       #2
          "comp":{ "type":"completion" }   #3
        }
      }
    }
  }
}

This mapping creates subject as text and adds keyword and completion representations under the fields object. section 4.7

Use the additional representations deliberately:

  • Use the parent field, such as subject, when analyzed text is appropriate. section 4.7
  • Use a named subfield, such as title.keyword or subject.kw, when exact values are required; keyword values remain unanalyzed unless normalization is configured. section 4.1.2 section 4.7
  • Do not confuse this mapping object with the search-response fields object, which explicitly selects returned fields such as title and rating; those values appear as JSON arrays. section 8.8.5

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains syntax, dot-notation access, and keyword analysis, but stops short of deeper indexing internals.
Examples
Uses email subjects and movie titles mapped as text with keyword or completion subfields.
What it assumes
Assumes basic field data types and mapping, while explaining multi-typed fields and keyword behavior directly.
What you can do after
Build it from scratch by defining multi-typed Elasticsearch fields and querying each representation through dot notation.
How it connects
Connects multi-field mappings with data types, text, keyword, completion, dynamic mapping, and exact-value search.

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.