# How to invoke python script from elasticsearc output plugin

**URL:** <https://discuss.elastic.co/t/how-to-invoke-python-script-from-elasticsearc-output-plugin/104408>\
**Category:** Logstash\
**Created:** [October 18, 2017, 2:08pm UTC](https://discuss.elastic.co/t/how-to-invoke-python-script-from-elasticsearc-output-plugin/104408 "2017-10-18T14:08:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lefteris\_Karamoulas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lefteris_karamoulas/32/23155_2.png) [@Lefteris\_Karamoulas](https://discuss.elastic.co/u/Lefteris_Karamoulas)\
**Post date:** [October 18, 2017, 2:08pm UTC](https://discuss.elastic.co/t/how-to-invoke-python-script-from-elasticsearc-output-plugin/104408/1 "2017-10-18T14:08:32Z")

</div>

Hello,

At the moment i have logstash and elasticsearch. My logstash uses as input the twitter input plug in and as output i have the elasticsearch plugin. My goal is to invoke a python script before the data is stored in my elasticsearch. Now the script is something simple like adding a new field with static text just to see it working but later on it will do some text/sentiment analysis. So i dont want to use the ruby filter. I dont get any errors i can see the twitter posts in my elasticsearch but without the new field that i expect. (i also made the script write to file just to see if it is invoked an nothing). I have installed the python plugin in elasticsearch and my script is inside the config/scripts module. My logstash configuration so far is  
input {  
twitter{  
consumer\_key =\> ""  
consumer\_secret =\> ""  
oauth\_token =\> ""  
oauth\_token\_secret =\> ""  
keywords =\> ["webinar"]  
languages =\> ["en"]  
full\_tweet =\> true  
}  
}  
filter{  
if "webinar" not in [text]{  
drop { }  
}  
if [user][lang]{  
ruby {  
code =\> 'event.set("language", event.get("[user][lang]"))'  
}  
}  
if [user][time\_zone]{  
ruby {  
code =\> 'event.set("timezone", event.get("[user][time\_zone]"))'  
}  
}  
if [user][location]{  
ruby {  
code =\> 'event.set("location", event.get("[user][location]"))'  
}  
}  
prune {  
whitelist\_names =\> ["^created\_at$","^retweet\_count$","^text$","^language$","^timezone$","^location$"]  
}  
}  
output {  
stdout{codec =\> rubydebug}  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "twitterposts"  
script\_lang =\> "python"  
script\_type =\> "file"  
script =\> "[latlongcalc.py](http://latlongcalc.py)"  
}  
}  
Also if there is a smarter way to store specific nested fields from user without coping the value to a new field that would be also nice.  
Thank you in advance.

---

<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:** [November 15, 2017, 2:09pm UTC](https://discuss.elastic.co/t/how-to-invoke-python-script-from-elasticsearc-output-plugin/104408/2 "2017-11-15T14:09:26Z")

</div>

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