How to avoid some aggregation data (if not needed)

Hi, I have below aggregation:

"aggregations" : {
    "level1" : {
      "terms" : {
        "field" : "country",
        "size" : 0,
      },
      "aggregations" : {
        "orderAggs" : {
          "terms" : {
            "field" : "orderId",
            "size" : 0,
          },
          "aggregations" : {
            "totalQty" : {
              "max" : {
                "field" : "targetQty"
              }
            },
            "timeFilterAggs" : {
              "filter" : {
                "range" : {
                  "timeTaken" : {
                    "from" : null,
                    "to" : 5000,
                    "include_lower" : true,
                    "include_upper" : true
                  }
                }
              },
              "aggregations" : {
                "processed" : {
                  "max" : {
                    "field" : "processedQty"
                  }
                }
              }
            }
          }
        },
        "sumProcessed" : {
          "sum_bucket" : {
            "buckets_path" : [ "order>timeFilter>processed" ]
          }
        },
        "sumTargeted" : {
          "sum_bucket" : {
            "buckets_path" : [ "order>totalQty" ]
          }
        },
        "processedRatio" : {
          "bucket_script" : {
            "script" : {
              "inline" : "(target != 0 && target != null)? processed / target * 100:0"
            },
            "buckets_path" : {
              "processed" : "sumProcessed",
              "target" : "sumTargeted"
            }
          }
        }
      }
    }
  }

The response:

   "aggregations": {
    "level1": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "IN",
          "doc_count": 4,
          "orderAggs": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
              {
                "key": "ID_1",
                "doc_count": 2,
                "totalQty": {
                  "value": 2
                },
                "timeFilterAggs": {
                  "doc_count": 2,
                  "processed": {
                    "value": 2
                  }
                }
              },
              {
                "key": "ID_2",
                "doc_count": 2,
                "totalQty": {
                  "value": 2
                },
                "timeFilterAggs": {
                  "doc_count": 2,
                  "processed": {
                    "value": 2
                  }
                }
              }
            ]
          },
          "sumProcessed": {
            "value": 4
          },
          "sumTargeted": {
            "value": 4
          },
          "processedRatio": {
            "value": 100.0
          }
        }]
	}
}

Here, I am basically interested in the processedRatio, but in the response I am getting the values for each aggregations and then the calculated value.
As I need only processedRatio, So

  1. Is there any way to avoid the some aggregation data(If not needed) as part of the
    response ?
  2. Is there any way we can get the response similar to
    below one -
  "aggregations": {
    "level1": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "IN",
          "doc_count": 77,
          "orderAggs": {
            //I don't need to include this as part of result, but I need this data for calculation
          },
          "sumProcessed": {
            "value": 4
          },
          "sumTargeted": {
            "value": 4
          },
          "processedRatio": {
            "value": 100.0
          }
        }]
	}
}
  1. This is needed to improve performance, as we are getting all the aggregation data which is taking part in calculation. So for large no. of records the data set will be huge though I am interested the calculated result("processedRatio").

Please put comments for any doubt in question. Thanks.

@dadoonet Hi David, Can you please help me with your thoughts on this ? Thanks

Please don't ping people like this and let the community decide to what they want and can answer. I believe someone will pick that one at some point.

Please read "be patient" section as well in

ok... I will take care next time.. and will wait for community to answer.. :slight_smile:

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