# How to call stored script from another script?

**URL:** <https://discuss.elastic.co/t/how-to-call-stored-script-from-another-script/179920>\
**Category:** Elasticsearch\
**Created:** [May 7, 2019, 8:24am UTC](https://discuss.elastic.co/t/how-to-call-stored-script-from-another-script/179920 "2019-05-07T08:24:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhmtnlr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mhmtnlr/32/45665_2.png) [@mhmtnlr](https://discuss.elastic.co/u/mhmtnlr)\
**Post date:** [May 7, 2019, 8:24am UTC](https://discuss.elastic.co/t/how-to-call-stored-script-from-another-script/179920/1 "2019-05-07T08:24:25Z")

</div>

Hey,  
I have a stored script which does some calculation and returns a number. I'm using it to populate a scripted field. And I need to use the pretty much same script for filtering out the results. Firstly, I try to access the scripted field in order to use it for filtering but apparently, we cannot access the scripted field from other scripts.  
So, I wonder if it is possible to call the stored script from another script or not?

> // something like this  
> {  
> "filter": {  
> "script": {  
> "script": {  
> "source": "\_scripts. **foo\_stored\_script** (params) \> THRESHOLD"  
> }}}}

Is it possible to do this? Or is there an easier way to do something like this?

Thanks

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [May 10, 2019, 2:46pm UTC](https://discuss.elastic.co/t/how-to-call-stored-script-from-another-script/179920/2 "2019-05-10T14:46:07Z")

</div>

Unfortunately, this is not possible. There is no infrastructure to call scripts from within scripts in ES. My recommendation would be to create a method within one the Painless scripts that can be copy/pasted to others if the same code needs to be re-used.

---

<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:** [June 7, 2019, 2:46pm UTC](https://discuss.elastic.co/t/how-to-call-stored-script-from-another-script/179920/3 "2019-06-07T14:46:11Z")

</div>

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