# When to use "file-based scripts" in elasticsearch?

**URL:** <https://discuss.elastic.co/t/when-to-use-file-based-scripts-in-elasticsearch/155915>\
**Category:** Elasticsearch\
**Created:** [November 8, 2018, 3:04pm UTC](https://discuss.elastic.co/t/when-to-use-file-based-scripts-in-elasticsearch/155915 "2018-11-08T15:04:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elhamroshan](https://avatars.discourse-cdn.com/v4/letter/e/4af34b/32.png) [@elhamroshan](https://discuss.elastic.co/u/elhamroshan)\
**Post date:** [November 8, 2018, 3:04pm UTC](https://discuss.elastic.co/t/when-to-use-file-based-scripts-in-elasticsearch/155915/1 "2018-11-08T15:04:19Z")

</div>

Hi,

I need to check if fieldX exists in each document in the Index. Then for those which it doesn't, I would like to get the value of fieldY of the same document, run a python function on that field and store the result in the fieldX.

doc1.fieldX = doesn't exist  
doc1.fieldY = "This is a text that a python function will analyse it"

pythonFunction(doc1.fieldY) = ["text","python","function"]

In the end, after the update, I should have something like:

doc1.fieldX = ["text","python","function"]  
doc1.fieldY = "This is a text that a python function will analyse it"

I just learnt about "file-based scripts" concept in elasticsearch. Wondering if it's better that I use this concept and update the data or I'd better handle everything from Python(connect to db, read data, get the value of each fieldY, update fieldX accordingly)?

Thanks,  
Ellie

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 9, 2018, 11:14am UTC](https://discuss.elastic.co/t/when-to-use-file-based-scripts-in-elasticsearch/155915/2 "2018-11-09T11:14:54Z")

</div>

file based scripts have been removed. Also, you cannot run python code within Elasticsearch. So you might want to search for documents missing a certain field (by negating the [exists query](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-exists-query.html)) and then use the [update API](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/docs-update.html). Or you can check if the requirement you need to do can be done within painless, the scripting language used within Elasticsearch - which might not be the case if you do something like NLP processing.

Hope this helps!

---

<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:** [December 7, 2018, 11:14am UTC](https://discuss.elastic.co/t/when-to-use-file-based-scripts-in-elasticsearch/155915/3 "2018-12-07T11:14:56Z")

</div>

Closed on December 7, 2018, 11:14am UTC

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