# Scripted Fields in Kibana Not Working as Expected

**URL:** <https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working-as-expected/287221>\
**Category:** Kibana\
**Created:** [October 20, 2021, 3:58pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working-as-expected/287221 "2021-10-20T15:58:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alecm](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@alecm](https://discuss.elastic.co/u/alecm)\
**Post date:** [October 20, 2021, 3:58pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working-as-expected/287221/1 "2021-10-20T15:58:59Z")

</div>

Hi, I'm new to Kibana and am testing out scripted fields functionality. I've used them a few times in the past, but am running into strange issues today.

Documents in my dataset contain a text key [classification\_info]. I want to indicate in a new field called [price\_percentage] if the [classification\_info] contains the string "price\_percentage".  
However when writing a script using  
`doc['classification_info.keyword'].value.contains("price_percentage")`  
I see unexpected behavior. The result in the sample viewer is an empty array, and If I try to view results in Discover I get an error.

As a sanity check, I wrote the below scripted field to see whether or not my documents indeed have classification\_info. It they do, I'll return 1, if not, I'll return 0

 ![Screen Shot 2021-10-20 at 12.00.32 PM](https://us1.discourse-cdn.com/elastic/original/3X/9/2/926886ea19dcd3db9d2a32c522576b28fff0baad.png)

As you can see from the sample results, the first 10 documents checked have classification\_info:

 ![Screen Shot 2021-10-20 at 11.54.20 AM](https://us1.discourse-cdn.com/elastic/original/3X/0/b/0bf6628f6498c0202a8a289d113d03633bb2593b.png)

Next up I tested to see what happens when I try to return classification\_info using the following modified script:

 ![Screen Shot 2021-10-20 at 11.55.44 AM](https://us1.discourse-cdn.com/elastic/original/3X/9/2/922c9b36254530f7d6c0cd34126f794f3ee25793.png)

However, the resulting sample preview returns an empty array. This is strange because as we saw from the first script, we've already confirmed that these documents should include the field.

More concerning, if I save the script as is, when I try to review this index in the Discover pane I see the following error.

 ![Screen Shot 2021-10-20 at 11.57.02 AM](https://us1.discourse-cdn.com/elastic/original/3X/2/4/2438dca976818e2a52537e1b0d1d8677cb0e0f76.jpeg)

Please let me know if I need to provide any more details to further clarify.

---

<div class="post-metadata">

**Author:** ![Iker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iker/32/91708_2.png) [@Iker](https://discuss.elastic.co/u/Iker)\
**Post date:** [October 20, 2021, 6:30pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working-as-expected/287221/2 "2021-10-20T18:30:53Z")

</div>

Does the "classification\_info" exist as a keyword field type?. Please provide some sample documents and the Elastic Version that you're using.

---

<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 17, 2021, 6:31pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working-as-expected/287221/3 "2021-11-17T18:31:04Z")

</div>

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