Hi, I'm new to painless and needed some assistance.
Having this query :
GET index1/_search/
{
"size": 0,
"aggs": {
"attrs_root": {
"nested": {
"path": "business_index_jd_list_agg"
},
"aggs": {
"attrs": {
"terms": {
"field": "jdl_id"
},
"aggs": {
"sumOfQuantity" : {
"sum" : {
"field" : "value"
}
}
}
}
}
}
}
}
and these results from that query :
[...]
aggregations" : {
"attrs_root" : {
"doc_count" : 5,
"attrs" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : -666,
"doc_count" : 1,
"sumOfQuantity" : {
"value" : 55.0
}
},
{
"key" : 93,
"doc_count" : 1,
"sumOfQuantity" : {
"value" : 25.0
}
},
{
"key" : 94,
"doc_count" : 1,
"sumOfQuantity" : {
"value" : 35.0
}
},
{
"key" : 112,
"doc_count" : 1,
"sumOfQuantity" : {
"value" : 45.0
}
},
{
"key" : 158,
"doc_count" : 1,
"sumOfQuantity" : {
"value" : 40.0
}
}
]
}
}
}
}
How can I use that query and navigate through those results using a painless script to achieve to update each document in the index with that agregated info. Something like this:
{
"jdl_id" : -666,
"value" : 55.0
}
},
{
"jdl_id" : 93,
"value" : 25.0
}
},
{
"jdl_id" : 94,
"value" : 35.0
}
},
{
"jdl_id" : 112,
"value" : 45.0
}
},
{
"jdl_id" : 158,
"value" : 40.0
}
Thank you.