# Is it possible to produce a script field for use in an Aggregation

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-produce-a-script-field-for-use-in-an-aggregation/67037>\
**Category:** Elasticsearch\
**Created:** [November 23, 2016, 10:11pm UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-script-field-for-use-in-an-aggregation/67037 "2016-11-23T22:11:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ray\_Mauge](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Ray\_Mauge](https://discuss.elastic.co/u/Ray_Mauge)\
**Post date:** [November 23, 2016, 10:11pm UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-script-field-for-use-in-an-aggregation/67037/1 "2016-11-23T22:11:48Z")

</div>

I want to use a script field as part of an aggregation. But this script field needs to use a field then lookup some external data to return the new field.

How can this be realized?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 23, 2016, 10:28pm UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-script-field-for-use-in-an-aggregation/67037/2 "2016-11-23T22:28:43Z")

</div>

> [@Ray\_Mauge](#):
>
> How can this be realized?

For the most part we try our best not to allow something like that because it'll make the search super duper slow and block a thread that isn't designed to be blocked.

Your best bet is getting all the data up front and passing it as a parameter to the script if it is small or updating the documents with the data if the data is large.

---

<div class="post-metadata">

**Author:** ![Ray\_Mauge](https://avatars.discourse-cdn.com/v4/letter/r/74df32/32.png) [@Ray\_Mauge](https://discuss.elastic.co/u/Ray_Mauge)\
**Post date:** [November 24, 2016, 12:40am UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-script-field-for-use-in-an-aggregation/67037/3 "2016-11-24T00:40:44Z")

</div>

Yes, I am aware of the performance implications, but the search is not time sensitive. I have considered those options but unfortunately they are not available.  
I want to know how I could go about coding this requirement. I have tried using a Java Native Plugin but I'm not certain what interface to implement.  
Thanks.

---

<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:** [December 22, 2016, 12:40am UTC](https://discuss.elastic.co/t/is-it-possible-to-produce-a-script-field-for-use-in-an-aggregation/67037/4 "2016-12-22T00:40:47Z")

</div>

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