How it works...

Field types must be mapped to one of the Elasticsearch base types, and options about how the field must be indexed need to be added.

The following table is a reference for the mapping types:

 

Depending on the data type, it's possible to give explicit directives to Elasticsearch when processing the field for better management. The most used options are as follows:

  • store (default false): This marks the field to be stored in a separate index fragment for fast retrieval. Storing a field consumes disk space, but reduces computation if you need to extract it from a document (that is, in scripting and aggregations). The possible values for this option are false and true.
The stored fields are faster than others in aggregations.
  • index: This defines whether or not the field should be indexed. The possible values for this parameter are true and false. Index fields are not searchable (default true).
  • null_value: This defines a default value if the field is null.
  • boost: This is used to change the importance of a field (default 1.0).
Boost works on a term level only, so it's mainly used in term, terms, and match queries.
  • search_analyzer: This defines an analyzer to be used during the search. If not defined, the analyzer of the parent object is used (default null).
  • analyzer: This sets the default analyzer to be used (default null).
  • include_in_all: This marks the current field to be indexed in the special _all field (a field that contains the concatenated text of all fields) (default true).
  • norms: This controls the Lucene norms. This parameter is used to better score queries. If the field is used only for filtering, it's best practice to disable it to reduce resource usage (default true for analyzed fields and false for not_analyzed ones).
  • copy_to: This allows you to copy the content of a field to another one to achieve functionalities, similar to the _all field.
  • ignore_above: This allows you to skip the indexing string that's bigger than its value. This is useful for processing fields for exact filtering, aggregations, and sorting. It also prevents a single term token from becoming too big and prevents errors due to the Lucene term byte-length limit of 32766 (default 2147483647).