- Elasticsearch 7.0 Cookbook(Fourth Edition)
- Alberto Paro
- 210字
- 2021-06-24 14:52:07
How it works...
During indexing, when Elasticsearch processes a fields property of type multifield, it reprocesses the same field for every subfield defined in the mapping.
To access the subfields of a multifield, we have a new path built on the base field plus the subfield name. If we consider the preceding example, we have the following:
- name: This points to the default multifield subfield-field (the keyword one)
- name.tk: This points to the standard analyzed (tokenizated) text field
- name.code: This points to a field analyzed with a code extractor analyzer
As you may have noticed in the preceding example, we have changed the analyzer to introduce a code extractor analyzer that allows you to extract the item code from a string.
Using the multifield, if we index a string such as Good Item to buy - ABC1234, we'll have the following:
- name = Good Item to buy - ABC1234 (useful for sorting)
- name.tk= ["good", "item", "to", "buy", "abc1234"] (useful for searching)
- name.code = ["ABC1234"] (useful for searching and faceting)
In the case of the code analyzer, if the code is not found in the string, no tokens are generated. This makes it possible to develop solutions that carry out information retrieval tasks at index time and uses these at search time.