# Preloaded scripts example

**URL:** https://discuss.elastic.co/t/preloaded-scripts-example/10633
**Category:** Elasticsearch
**Created:** [February 6, 2013, 9:12am UTC](https://discuss.elastic.co/t/preloaded-scripts-example/10633 "2013-02-06T09:12:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![andrexus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrexus/32/2502_2.png) [@andrexus](https://discuss.elastic.co/u/andrexus)
#### Post date: [February 6, 2013, 9:12am UTC](https://discuss.elastic.co/t/preloaded-scripts-example/10633/1 "2013-02-06T09:12:26Z")

</div>

Hi! Could someone show a simple script (javascript, python) that is stored  
in scripts directory and takes some arguments? Could it be a user-defined  
function? Some example of script and its usage would be very helpful.  
Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![rastro](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@rastro](https://discuss.elastic.co/u/rastro)
#### Post date: [October 8, 2013, 6:51pm UTC](https://discuss.elastic.co/t/preloaded-scripts-example/10633/2 "2013-10-08T18:51:01Z")

</div>

I have a query like this:

{  
"query": {  
...  
},  
"facets" : {  
"tag": {  
"terms": {  
"field": "timers",  
"script": "myscript",  
"params": {  
"tag" : "foo"  
},  
"lang": "python"  
}  
}  
}  
}

Which calls myscript.py on the server. The python variable 'tag' is set to  
the value 'foo' when the script starts.

My script doesn't do everything that I want (since I've also been unable to  
find any examples), but it does do this part properly...

Note that you have to restart ES when you make changes to the script.

On Wednesday, February 6, 2013 1:12:26 AM UTC-8, andrexus wrote:

> Hi! Could someone show a simple script (javascript, python) that is stored  
> in scripts directory and takes some arguments? Could it be a user-defined  
> function? Some example of script and its usage would be very helpful.  
> Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![bikrant](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bikrant](https://discuss.elastic.co/u/bikrant)
#### Post date: [June 30, 2015, 7:22pm UTC](https://discuss.elastic.co/t/preloaded-scripts-example/10633/3 "2015-06-30T19:22:47Z")

</div>

@rastro can you please share the content of myscript.py

I'm trying to write a script that will extract some content based on the parameter passed to the script and return that content as a new field in the response.

---

<div class="post-metadata">

### Author: ![rastro](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@rastro](https://discuss.elastic.co/u/rastro)
#### Post date: [June 30, 2015, 8:26pm UTC](https://discuss.elastic.co/t/preloaded-scripts-example/10633/4 "2015-06-30T20:26:35Z")

</div>

Sorry, @bikrant, but I don't even remember what project that was for 9 months ago ☹

---

<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 6, 2017, 12:04am UTC](https://discuss.elastic.co/t/preloaded-scripts-example/10633/5 "2017-07-06T00:04:28Z")

</div>


