Is there a way to add a custom key and value to bucket response like the one below:
{
"took" : 7685,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"level_two" : {
"doc_count" : 308153,
"bg_count" : 1079172,
"buckets" : [
{
"key" : "Español",
"doc_count" : 89027,
"score" : 0.7228597097913709,
"bg_count" : 89027
},
{
"key" : "Deutsch",
"doc_count" : 48543,
"score" : 0.39414760569717644,
"bg_count" : 48543
},
{
"key" : "Français",
"doc_count" : 36772,
"score" : 0.29857231231478437,
"bg_count" : 36772
},
{
"key" : "Català",
"doc_count" : 23194,
"score" : 0.18832498128546465,
"bg_count" : 23194
},
{
"key" : "Italiano",
"doc_count" : 23188,
"score" : 0.18827626394961433,
"bg_count" : 23188
}
]
}
}
}
The desired response:
{
"took" : 7685,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"level_two" : {
"doc_count" : 308153,
"bg_count" : 1079172,
"buckets" : [
{
"custom_key": "All the same text",
"key" : "Español",
"doc_count" : 89027,
"score" : 0.7228597097913709,
"bg_count" : 89027
},
{
"custom_key": "All the same text",
"key" : "Deutsch",
"doc_count" : 48543,
"score" : 0.39414760569717644,
"bg_count" : 48543
},
{
"custom_key": "All the same text",
"key" : "Français",
"doc_count" : 36772,
"score" : 0.29857231231478437,
"bg_count" : 36772
},
{
"custom_key": "All the same text",
"key" : "Català",
"doc_count" : 23194,
"score" : 0.18832498128546465,
"bg_count" : 23194
},
{
"custom_key": "All the same text",
"key" : "Italiano",
"doc_count" : 23188,
"score" : 0.18827626394961433,
"bg_count" : 23188
}
]
}
}
}
The custom_key
will be the same for every bucket.