It is often useful to index the same field in different ways for different purposes. This is the purpose of multi-fields. For instance, a string field could be mapped as a text field for full-text search, and as a keyword field for sorting or aggregations:
PUT index_test
{
"mappings": {
"_doc": {
"properties": {
"city": {
"type": "text", //The city field can be used for full text search.
"fields": {
"raw": { //The city.raw field is a keyword version of the city field.
"type": "keyword"//The city.raw field can be used for sorting and aggregations
}
}
}
}
}
}
}
Thus we can use the city field for full text search and city.raw field for sorting and aggregations.
What if we need the attribute itself to have 2 different types?
Let's say we have an attribute Org_Id, it has long type in DB but now we need to do full-text search to it like below graph shows.
We cannot index the attribute by just setting its type as "text" for someday in the future we would need its numberic type for range/comprison calculation.
We can index the attribute id like below and post some data to it:
It is often useful to index the same field in different ways for different purposes. This is the purpose ofmulti-fields. For instance, astringfield could be mapped as atextfield for full-text sea...