# Compare a string and number in Scripted Field

**URL:** <https://discuss.elastic.co/t/compare-a-string-and-number-in-scripted-field/86807>\
**Category:** Kibana\
**Created:** [May 23, 2017, 12:38pm UTC](https://discuss.elastic.co/t/compare-a-string-and-number-in-scripted-field/86807 "2017-05-23T12:38:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![magerRV](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@magerRV](https://discuss.elastic.co/u/magerRV)\
**Post date:** [May 23, 2017, 12:38pm UTC](https://discuss.elastic.co/t/compare-a-string-and-number-in-scripted-field/86807/1 "2017-05-23T12:38:32Z")

</div>

Hey all,  
I want to compare a string and an number (integer) inside a scripted field. I know I have to convert the field from string to integer. I just dont know the syntax for that and dont find any result.

The characters of String Field are all numbers so it should work if I get the syntax correct.

my current code:  
{  
"convert": {  
"field" : "StringField",  
"type": "integer"  
}  
}

doc['StringField'].value == doc['NumberField'].value

Thanks for help!

---

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [May 26, 2017, 2:44pm UTC](https://discuss.elastic.co/t/compare-a-string-and-number-in-scripted-field/86807/2 "2017-05-26T14:44:08Z")

</div>

I created a scripted field of `type: number` and in the script I used a `text` field `response.raw` (which are http response code numbers but stored as text). And used `Integer.parseInt` on the doc value of it. When I go to Discover I see the numeric result for this scripted field. Does that help?

 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/f/ef9eec833f22f3740baf38d44ce637d66ca99e40.png)

Regards,  
Lee

---

<div class="post-metadata">

**Author:** ![magerRV](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@magerRV](https://discuss.elastic.co/u/magerRV)\
**Post date:** [May 31, 2017, 1:37pm UTC](https://discuss.elastic.co/t/compare-a-string-and-number-in-scripted-field/86807/3 "2017-05-31T13:37:19Z")

</div>

I got a solution by myselfe, you can just parse it from Integer to String

e.g. :

doc['String.keyword'].value == " " + doc['Number'].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:** [June 28, 2017, 1:38pm UTC](https://discuss.elastic.co/t/compare-a-string-and-number-in-scripted-field/86807/4 "2017-06-28T13:38:06Z")

</div>

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