Kibana script
POST test1/_doc/1
{
"COLOR": {
"value": "Rose",
"order": 2
}
}
POST test1/_doc/2
{
"COLOR": {
"value": "Jaune",
"order": 1
}
}
POST test1/_doc/3
{
"COLOR": {
"value": "Bleu",
"order": 3
}
}
GET test1/_search
{
"query": {
"match_all": {}
},
"aggs": {
"group_by_color": {
"terms": {
"field": "COLOR.value.keyword"
}
}
}
}
Result :
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "test1",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"COLOR" : {
"value" : "Rose",
"order" : 2
}
}
},
{
"_index" : "test1",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"COLOR" : {
"value" : "Jaune",
"order" : 1
}
}
},
{
"_index" : "test1",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"COLOR" : {
"value" : "Bleu",
"order" : 3
}
}
}
]
},
"aggregations" : {
"group_by_color" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Bleu",
"doc_count" : 1
},
{
"key" : "Jaune",
"doc_count" : 1
},
{
"key" : "Rose",
"doc_count" : 1
}
]
}
}
}
Wanted result :
On aggregations.group_by_color.buckets
, i want my aggregation values ordered by COLOR.order