Performing sum after terms aggregation for 1.5m buckets

Hello Team,

I am performing a terms aggregation on two fields i.e EntityCode and ItemNumber as shown in the example below. And over that I'm calculating sum on few fields and then applying a formula to the sum fields using bucket_script. As the default size for the terms aggregation bucket is 10 and the total buckets I'm expecting in my scenario are around 1.4m. The result on the computed value is only considered for 10 buckets. Is there any way to compute the same, Please suggest a work around if any or highlight if I'm doing anything wrong.

Following is the query

        GET salesdemo_4/_search`
        {
          "from": 0,
          "size": 0,
          "query": {
            "bool": {}
          },
          "aggs": {
            "OrgField": {
              "terms": {
                "field": "OrgField.Plant.EntityCode.keyword",
                "size": 10
              },
              "aggs": {
                "ItemNumber": {
                  "terms": {
                    "field": "ItemNumber.keyword",
                    "size": 10
                  },
                  "aggs": {
                    "QualityInspection": {
                      "sum": {
                        "field": "QualityInspection"
                      }
                    },
                    "Ordered": {
                      "sum": {
                        "field": "Ordered"
                      }
                    },
                    "Reserved": {
                      "sum": {
                        "field": "Reserved"
                      }
                    },
                    "Unrestricted": {
                      "sum": {
                        "field": "Unrestricted"
                      }
                    },
                    "MovingAvgPrice": {
                      "sum": {
                        "field": "MovingAvgPrice"
                      }
                    },
                    "total_mov_avg": {
                      "bucket_script": {
                        "script": "( params.QualityInspection+ params.Ordered+ params.Reserved+ params.Unrestricted) * params.MovingAvgPrice",
                        "buckets_path": {
                          "QualityInspection": "QualityInspection",
                          "Ordered": "Ordered",
                          "Reserved": "Reserved",
                          "Unrestricted": "Unrestricted",
                          "MovingAvgPrice": "MovingAvgPrice"
                        }
                      }
                    }
                  }
                },
                "total_mov_avg": {
                  "sum_bucket": {
                    "buckets_path": "ItemNumber>total_mov_avg"
                  }
                }
              }
            },
            "total_mov_avg": {
              "sum_bucket": {
                "buckets_path": "OrgField>total_mov_avg"
              }
            }
          }
        }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.