# Unable to create a script field

**URL:** <https://discuss.elastic.co/t/unable-to-create-a-script-field/280512>\
**Category:** Kibana\
**Created:** [August 5, 2021, 8:47am UTC](https://discuss.elastic.co/t/unable-to-create-a-script-field/280512 "2021-08-05T08:47:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rammohan](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@Rammohan](https://discuss.elastic.co/u/Rammohan)\
**Post date:** [August 5, 2021, 8:47am UTC](https://discuss.elastic.co/t/unable-to-create-a-script-field/280512/1 "2021-08-05T08:47:45Z")

</div>

Hello,

I am trying to create a simple script field to display the key size of the SSL certificate, the key size value differs between 256 to 270 bytes, so I created the below script field.

if (doc['ssl\_certificate\_subject\_key\_size.keyword'].value \>= 256 && doc['ssl\_certificate\_subject\_key\_size.keyword'].value \<= 270 )  
return "2048";

After I configured this scripted field, I am getting the error "llegal\_state\_exception a document doesn't have a value for this field"

Error:  
"reason": "No field found for [ssl\_certificate\_subject\_key\_size.keyword] in mapping

Can someone help to sort out this issue?

Thanks,  
Ram Mohan

---

<div class="post-metadata">

**Author:** ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)\
**Post date:** [August 10, 2021, 5:46pm UTC](https://discuss.elastic.co/t/unable-to-create-a-script-field/280512/2 "2021-08-10T17:46:54Z")

</div>

> [@Rammohan](#):
>
> (doc['ssl\_certificate\_subject\_key\_size.keyword

Welcome to the community @Rammohan !  
There are two issues I see in the script you're trying to add:

1. [keyword](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html) fields are strings, so a numeric range comparison won't work for those. You'll need to change the mapping to a [number](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html).
2. you'll need to check your index mapping and use a field that is mapped.

I don't know what your current mapping looks like or if you can reindex your data into a new index with updated mappings.  
If you can't reindex the data, then try using a runtime field to cast the data to a numeric value.

---

<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:** [September 7, 2021, 5:47pm UTC](https://discuss.elastic.co/t/unable-to-create-a-script-field/280512/3 "2021-09-07T17:47:17Z")

</div>

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