- Elasticsearch 7.0 Cookbook(Fourth Edition)
- Alberto Paro
- 163字
- 2021-06-24 14:52:07
How to do it...
To define a multifield property, we need to define a dictionary containing the fields subfield. The subfield with the same name as a parent field is the default one.
If we consider the item of our order example, we can index the name in this way:
{
"name": {
"type": "keyword",
"fields": {
"name": {"type": "keyword"},
"tk": {"type": "text"},
"code": {"type": "text","analyzer": "code_analyzer"}
}
},
If we already have a mapping stored in Elasticsearch and we want to migrate the fields in a multi-field property, it's enough to save a new mapping with a different type, and Elasticsearch provides the merge automatically. New subfields in the fields property can be added without problems at any moment, but the new subfields will be available in searching/aggregation only to newly indexed documents.
When you add a new subfield to already indexed data, you need to reindex your record to ensure you have it correctly indexed for all your records.