Elasticsearch 7.0 Cookbook(Fourth Edition)
上QQ阅读APP看书,第一时间看更新

There's more...

In the previous version of Elasticsearch, the standard mapping for the string was string. In version 5.x, the string mapping is deprecated and migrated to keyword and text mappings.

In Elasticsearch version 6.x, as shown in the Using explicit mapping creation recipe, the explicit inferred type for a string is a multifield mapping:

  • The default processing is text. This mapping allows textual queries (that is, term, match, and span queries). In the example provided in the Using explicit mapping creation recipe, this was name.
  • The keyword subfield is used for keyword mapping. This field can be used for exact term matching and for aggregation and sorting. In the example provided in the Using explicit mapping creation recipe, the referred field was name.keyword.

Another important parameter, available only for text mapping, is the term_vector (the vector of terms that compose a string. Refer to the Lucene documentation for further details at http://lucene.apache.org/core/6_1_0/core/org/apache/lucene/index/Terms.html).

The term_vector can accept the following values:

  • no: This is the default value, skip term vector
  • yes: This is the store term vector
  • with_offsets: This is the store term vector with token offset (start, end position in a block of characters)
  • with_positions: This is used to store the position of the token in the term vector
  • with_positions_offsets: This stores all term vector data
Term vectors allow fast highlighting, but consume disk space due to storing of additional text information. It's a best practice to only activate in fields that require highlighting, such as title or document content.