1

I'm new to elastic/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
            },
          [...]
        ]
      }
    }
  }
}

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
            }
          },
[...]

Thank you.

0 Answers0