ElasticSearch 5.x Sorting on Text Field Issue ElasticSearch 5.x Sorting on Text Field Issue elasticsearch elasticsearch

ElasticSearch 5.x Sorting on Text Field Issue


Use this settings instead for 5.x. "keyword" is the new type for not-analyzed string.

{   "mappings": {     "doc": {       "dynamic_templates": [         {           "strings": {             "match_mapping_type": "string",             "mapping": {               "type": "text",               "fields": {                 "raw": {                   "type": "keyword",                   "ignore_above": 256                 },                 "english": {                   "type": "text",                   "analyzer": "english"                 }               }             }           }         }       ]     }   } }

Here's the explanation I got from Lee Hinman in ElasticSearch forum.

If you index a string with no mapping, ES in 5.0+ now automatically creates a text version and a keyword version (under .keyword) of the field.

This is actually rather confusing some match_mapping_type doesn't understand value "text".

There's a disconnect for this, the "dynamic" type used for match_mapping_type is the type of the field, not necessarily the ES type. For instance, match_mapping_type only supports "long", not "integer" because it maps to the data type rather than an ES type. So even though ES itself uses "text" and "keyword", the data type is still a "string".

I agree this is confusing, there was a PR here: https://github.com/elastic/elasticsearch/pull/17285 for 5.0+ that adds deprecation logging for this, and I opened https://github.com/elastic/elasticsearch/pull/22090 so 6.0 will throw an exception when an unrecognized type is used.