Is it possible to make the key
of the resulting aggregation be the int
value returned by the script instead of a string
?
See this example, but using dayOfMonth
or hourOfDay
instead of dayOfWeek
, so there are more than 10 values, so the result ends up being ordered, "1", "10", "11", ..." instead of
1, 2, 3,...`.
Here's an example of the full call:
POST /sales/_search?size=0
{
"aggs": {
"dayOfMonth": {
"terms": {
"script": {
"lang": "painless",
"source": "doc['date'].value.dayOfMonth"
}
}
}
}
}
And an example response:
{
...
"aggregations": {
"dayOfWeek": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "1",
"doc_count": 4
},
{
"key": "10",
"doc_count": 3
},
{
"key": "2",
"doc_count": 2
}
]
}
}
}