I have similar case like here and here2.
I am trying to achive alphabetical sorting (case insensitive) with original value from aggregation.
Simplified example mapping:
PUT test_data
{
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"name@String": {
"properties": {
"values": {
"properties": {
"defaultValue": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
},
"sortword": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "case_insensitive"
}
}
},
"translations": {
"properties": {
"0": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
},
"sortword": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "case_insensitive"
}
}
}
}
}
}
}
}
}
}
},
"settings": {
"analysis": {
"normalizer": {
"case_insensitive": {
"filter": [
"lowercase"
],
"type": "custom"
}
}
}
}
}
My test data:
POST test_data/_doc/
{
"name@String": {
"values": {
"defaultValue": "CCC",
"translations": {
"0": "CCC"
}
}
}
}
POST test_data/_doc/
{
"name@String": {
"values": {
"defaultValue": "bbb",
"translations": {
"0": "bbb"
}
}
}
}
POST test_data/_doc/
{
"name@String": {
"values": {
"defaultValue": "BBB",
"translations": {
"0": "BBB"
}
}
}
}
POST test_data/_doc/
{
"name@String": {
"values": {
"defaultValue": "aaa",
"translations": {
"0": "aaa"
}
}
}
}
POST test_data/_doc/
{
"name@String": {
"values": {
"defaultValue": "AAA",
"translations": {
"0": "AAA"
}
}
}
}
Terms aggregation Order paragraph says: Ordering the buckets alphabetically by their terms in an ascending manner.
Here is my aggregation_1:
POST test_data/_search
{
"query": {
"match_all": {}
},
"aggs": {
"names": {
"terms": {
"field": "name@String.values.translations.0.keyword",
"order": {
"_key": "asc"
}
}
}
},
"size": 0
}
Result:
AAA
BBB
CCC
aaa
bbb
Expected (order between cases does not matter):
AAA
aaa
bbb
BBB
CCC
Here is my aggregation_2:
POST test_data/_search
{
"query": {
"match_all": {}
},
"aggs": {
"names": {
"terms": {
"field": "name@String.values.translations.0.sortword",
"order": { "_key": "asc" }
}
}
},
"size": 0
}
Result:
aaa,
bbb,
ccc
I have tried to do something with pipelines, like sort by sortword and term keyword, but have no success.