# Getting error while creating scripted field

**URL:** <https://discuss.elastic.co/t/getting-error-while-creating-scripted-field/296221>\
**Category:** Kibana\
**Created:** [February 3, 2022, 6:37pm UTC](https://discuss.elastic.co/t/getting-error-while-creating-scripted-field/296221 "2022-02-03T18:37:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surya\_Raviraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/surya_raviraj/32/77606_2.png) [@Surya\_Raviraj](https://discuss.elastic.co/u/Surya_Raviraj)\
**Post date:** [February 3, 2022, 6:37pm UTC](https://discuss.elastic.co/t/getting-error-while-creating-scripted-field/296221/1 "2022-02-03T18:37:03Z")

</div>

Hi all,

I am creating a scripted field on an index that already has a bunch of scripted fields. After creating the scripted field I preview the results and see my desired results. For some reason, when I go back to the discover tab to check out my index I get a bad request. I am attaching a screenshot with the error. Any help would be appreciated. Please let me know.

Extra information: I am able to create scripted fields on other indexes that are on the same instance. I am also able to modify scripted fields on the index I am trying to create new scripted fields on.

 ![Screen Shot 2022-02-03 at 12.27.37 PM](https://us1.discourse-cdn.com/elastic/original/3X/8/d/8d103c5420e4b942b2df4aa06e87d535ad8bd9c5.png)

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [February 3, 2022, 6:44pm UTC](https://discuss.elastic.co/t/getting-error-while-creating-scripted-field/296221/2 "2022-02-03T18:44:21Z")

</div>

Hello,

Which version of the stack? Can you please post your script for the field? Are you logging in as the same user all times?

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![Surya\_Raviraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/surya_raviraj/32/77606_2.png) [@Surya\_Raviraj](https://discuss.elastic.co/u/Surya_Raviraj)\
**Post date:** [February 3, 2022, 6:54pm UTC](https://discuss.elastic.co/t/getting-error-while-creating-scripted-field/296221/3 "2022-02-03T18:54:40Z")

</div>

Version: 7.10.0  
Script: if(doc['stages'].empty){ return 0; }else{ if(doc['stages'].value == "Z5SPCreated"){ return 1; } else{ return 0; } }  
Yes, I'm logging in as the same user at all times.

Thank you for your quick response.

---

<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:** [March 3, 2022, 6:55pm UTC](https://discuss.elastic.co/t/getting-error-while-creating-scripted-field/296221/4 "2022-03-03T18:55:24Z")

</div>

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