How to filter out useless aggregation result when using pipeline aggregations

When using pipeline aggregations, there are useless returned values which consumpt too much memory.

Take the below query as example.

{
    "aggs" : {
        "sales_per_month" : {
            "date_histogram" : {
                "field" : "date",
                "interval" : "month"
            },
            "aggs": {
                "total_sales": {
                    "sum": {
                        "field": "price"
                    }
                },
                "t-shirts": {
                  "filter": {
                    "term": {
                      "type": "t-shirt"
                    }
                  },
                  "aggs": {
                    "sales": {
                      "sum": {
                        "field": "price"
                      }
                    }
                  }
                },
                "t-shirt-percentage": {
                    "bucket_script": {
                        "buckets_path": {
                          "tShirtSales": "t-shirts>sales",
                          "totalSales": "total_sales"
                        },
                        "script": "tShirtSales / totalSales * 100"
                    }
                }
            }
        }
    }
}

In this case, only "t-shirt-percentage" pipeline aggregation measure is in need. All the other measures are useless. Is there a way to filter out the useless measures before ES return to decrease the memory consumption of the query result?

Hi,

I'm not sure I understand the question correctly, what do do you mean by "the other measures are useless"? It looks like you need them for the script? If you only want to filter out the aggregation results in the query response, take a look at Respone Filtering, maybe that helps.

1 Like

Get it!

Thanks for your kindly help.