# Passing "\_agg" variable in scripted metric aggregation

**URL:** <https://discuss.elastic.co/t/passing--agg-variable-in-scripted-metric-aggregation/99168>\
**Category:** Elasticsearch\
**Created:** [September 1, 2017, 8:28pm UTC](https://discuss.elastic.co/t/passing--agg-variable-in-scripted-metric-aggregation/99168 "2017-09-01T20:28:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![reeselevine](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@reeselevine](https://discuss.elastic.co/u/reeselevine)\
**Post date:** [September 1, 2017, 8:28pm UTC](https://discuss.elastic.co/t/passing--agg-variable-in-scripted-metric-aggregation/99168/1 "2017-09-01T20:28:40Z")

</div>

Could someone explain the reasoning behind having to specify "\_agg" : {} if script parameters are specified in the scripted metric aggregation (from this page: [https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-aggregations-metrics-scripted-metric-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-aggregations-metrics-scripted-metric-aggregation.html)).

It seems like the \_agg variable should always start out as empty, so it would make sense to include it by default even if other parameters are specified. In the native Java API, I see in ScriptedMetricAggregatorFactory that the \_agg variable is passed in if no params are specified, so I was thinking it should just be passed in either way.

Maybe there's something I'm missing here, so thanks in advance for answering!

---

<div class="post-metadata">

**Author:** ![reeselevine](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@reeselevine](https://discuss.elastic.co/u/reeselevine)\
**Post date:** [September 1, 2017, 10:19pm UTC](https://discuss.elastic.co/t/passing--agg-variable-in-scripted-metric-aggregation/99168/2 "2017-09-01T22:19:47Z")

</div>

Found a pull request out for this, hopefully it gets added soon!

> <https://github.com/elastic/elasticsearch/pull/19863>

---

<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:** [September 29, 2017, 10:19pm UTC](https://discuss.elastic.co/t/passing--agg-variable-in-scripted-metric-aggregation/99168/3 "2017-09-29T22:19:59Z")

</div>

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