# Script vs Value Script in Terms, Range Aggregations

**URL:** <https://discuss.elastic.co/t/script-vs-value-script-in-terms-range-aggregations/88732>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 3:30pm UTC](https://discuss.elastic.co/t/script-vs-value-script-in-terms-range-aggregations/88732 "2017-06-08T15:30:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexer338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hexer338/32/47413_2.png) [@hexer338](https://discuss.elastic.co/u/hexer338)\
**Post date:** [June 8, 2017, 3:30pm UTC](https://discuss.elastic.co/t/script-vs-value-script-in-terms-range-aggregations/88732/1 "2017-06-08T15:30:16Z")

</div>

Hi, In the documentation of `Terms Aggregation`, `Range Aggregation`, there are 2 types of scripts: `Script` and `Value Script`.  
What is the difference between them ?  
Which script would perform better if i only need value of 1 field in script?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 8, 2017, 7:15pm UTC](https://discuss.elastic.co/t/script-vs-value-script-in-terms-range-aggregations/88732/2 "2017-06-08T19:15:37Z")

</div>

A value script is one that the `field` is specified in the aggregation, and the value of that field is passed into the script as `_value`. A normal script has access to the entire doc and would access a field value like `doc['myfield'].value`. There should be no appreciable difference.

---

<div class="post-metadata">

**Author:** ![hexer338](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hexer338/32/47413_2.png) [@hexer338](https://discuss.elastic.co/u/hexer338)\
**Post date:** [June 9, 2017, 4:08am UTC](https://discuss.elastic.co/t/script-vs-value-script-in-terms-range-aggregations/88732/3 "2017-06-09T04:08:23Z")

</div>

Thank you @rjernst

---

<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:** [July 7, 2017, 4:08am UTC](https://discuss.elastic.co/t/script-vs-value-script-in-terms-range-aggregations/88732/4 "2017-07-07T04:08:37Z")

</div>

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