# Scripted Field Painless

**URL:** <https://discuss.elastic.co/t/scripted-field-painless/309328>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 11, 2022, 2:31pm UTC](https://discuss.elastic.co/t/scripted-field-painless/309328 "2022-07-11T14:31:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FKarraz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fkarraz/32/80628_2.png) [@FKarraz](https://discuss.elastic.co/u/FKarraz)\
**Post date:** [July 11, 2022, 2:31pm UTC](https://discuss.elastic.co/t/scripted-field-painless/309328/1 "2022-07-11T14:31:46Z")

</div>

Good morning. I am having problems when generating a scripted field. The situation is as follows. Inside my index, I have "field1" and "field2", if "field1" = 0, "field2" does not exist, if "field1" = 1, "field2" contains an array of strings.

What I need, is to generate a scripted field that is equal to the array of strings of "field2", the problem is, that when "field1" goes from 1 to 0, "field2" disappears and the value of my scripted field becomes null.

Can you think of a solution for this situation?

Thank you very much.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 11, 2022, 3:08pm UTC](https://discuss.elastic.co/t/scripted-field-painless/309328/2 "2022-07-11T15:08:01Z")

</div>

A scripted field is evaluated at query time and is not persisted and do not change the document. If you need it to persist you probably need to set it in the document, e.g. using an ingest pipeline.

---

<div class="post-metadata">

**Author:** ![FKarraz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fkarraz/32/80628_2.png) [@FKarraz](https://discuss.elastic.co/u/FKarraz)\
**Post date:** [July 15, 2022, 6:18pm UTC](https://discuss.elastic.co/t/scripted-field-painless/309328/3 "2022-07-15T18:18:19Z")

</div>

Ok, thanks for your answer.

---

<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:** [August 12, 2022, 6:18pm UTC](https://discuss.elastic.co/t/scripted-field-painless/309328/4 "2022-08-12T18:18:51Z")

</div>

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