keyword fields are stored as it is so sorting on keyword fields is case sensitive.Normalizer with lowercase filter can be used to index keyword fields.
The normalizer property of keyword fields is similar to analyzer
except that it guarantees that the analysis chain produces a single
token.
Mapping:
{
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
}
}
}
}
Query: Both sort on name.keyword and term query on name.keyword will be case insensitive
{
"query": {
"match_all": {}
},
"sort": [
{
"name.keyword": {
"order": "asc"
}
}
]
}
Result:"
"hits" : [
{
"_index" : "index84",
"_type" : "_doc",
"_id" : "SBvLT3IB8mx5yKbJQ7EC",
"_score" : null,
"_source" : {
"name" : "Amit 111"
},
"sort" : [
"amit 111"
]
},
{
"_index" : "index84",
"_type" : "_doc",
"_id" : "SRvLT3IB8mx5yKbJULFl",
"_score" : null,
"_source" : {
"name" : "amit 111"
},
"sort" : [
"amit 111"
]
},
{
"_index" : "index84",
"_type" : "_doc",
"_id" : "ShvLT3IB8mx5yKbJaLFg",
"_score" : null,
"_source" : {
"name" : "Amit 222"
},
"sort" : [
"amit 222"
]
}
]