Mapping a multifield
Often, a field must be processed with several core types or in different ways. For example, a string field must be processed as analyzed for search and as not_analyzed for sorting. To do this, we need to define a multifield.
Multifield is a very powerful feature of mapping, because it allows the use of the same field in different ways.
Getting ready
You need a working ElasticSearch cluster.
How to do it...
To define a multifield we need to do the following:
Use
multi_fieldas type.Define a dictionary containing the subfields called
fields. The subfield with the same name of parent field is the default one.
If we consider the item of our order example, we can index the name as multi_field as shown in the following code:
"name": {
"type": "multi_field",
"fields": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"tk": {
"type": "string",
"index": "analyzed"
},
"code": {
"type": "string",
"index": "analyzed",
"analyzer":...