# Poor performance of native search script

**URL:** <https://discuss.elastic.co/t/poor-performance-of-native-search-script/41129>\
**Category:** Elasticsearch\
**Created:** [February 7, 2016, 2:53am UTC](https://discuss.elastic.co/t/poor-performance-of-native-search-script/41129 "2016-02-07T02:53:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [February 7, 2016, 2:53am UTC](https://discuss.elastic.co/t/poor-performance-of-native-search-script/41129/1 "2016-02-07T02:53:17Z")

</div>

Hi,

I may not be using it correctly but when I access source() from inn native (java) script implemented as a plugin from aggregations performance drops dramatically. For example for a small data set of 15000 documents when doing terms aggregation with my script it takes 1.5 seconds to complete. For test I returned from the script without accessing source() - just returned an int between 0 and 50 and it only takes few milliseconds. As soon as source() is involved it drops to over one second.

I suspect it is because of loading and parsing the source where I should have been using doc values in my script instead. Could you point me to an example or docs on how best to access document fields in native scripts?

PS: I need access to multiple document fields so value script is probably not an option

Thanks  
Alex

---

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [February 7, 2016, 3:08am UTC](https://discuss.elastic.co/t/poor-performance-of-native-search-script/41129/2 "2016-02-07T03:08:23Z")

</div>

Solved I should have been using doc() instead of source() elastic docs sample pushed me in wrong direction 🙂

---

<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 5, 2017, 11:18pm UTC](https://discuss.elastic.co/t/poor-performance-of-native-search-script/41129/3 "2017-07-05T23:18:24Z")

</div>


