# How to avoid some aggregation data (if not needed)

**URL:** <https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420>\
**Category:** Elasticsearch\
**Created:** [March 29, 2017, 7:16am UTC](https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420 "2017-03-29T07:16:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashant.bajpai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant.bajpai/32/16844_2.png) [@prashant.bajpai](https://discuss.elastic.co/u/prashant.bajpai)\
**Post date:** [March 29, 2017, 7:16am UTC](https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420/1 "2017-03-29T07:16:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prashant.bajpai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant.bajpai/32/16844_2.png) [@prashant.bajpai](https://discuss.elastic.co/u/prashant.bajpai)\
**Post date:** [March 29, 2017, 8:37am UTC](https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420/2 "2017-03-29T08:37:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 29, 2017, 8:50am UTC](https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420/3 "2017-03-29T08:50:23Z")

</div>

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

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

---

<div class="post-metadata">

**Author:** ![prashant.bajpai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant.bajpai/32/16844_2.png) [@prashant.bajpai](https://discuss.elastic.co/u/prashant.bajpai)\
**Post date:** [March 29, 2017, 9:03am UTC](https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420/4 "2017-03-29T09:03:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2017, 9:03am UTC](https://discuss.elastic.co/t/how-to-avoid-some-aggregation-data-if-not-needed/80420/5 "2017-04-26T09:03:26Z")

</div>

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