# Convert string to integer

**URL:** <https://discuss.elastic.co/t/convert-string-to-integer/277915>\
**Category:** Kibana\
**Created:** [July 6, 2021, 6:44am UTC](https://discuss.elastic.co/t/convert-string-to-integer/277915 "2021-07-06T06:44:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANKITA\_SAHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankita_saha/32/91152_2.png) [@ANKITA\_SAHA](https://discuss.elastic.co/u/ANKITA_SAHA)\
**Post date:** [July 6, 2021, 6:44am UTC](https://discuss.elastic.co/t/convert-string-to-integer/277915/1 "2021-07-06T06:44:26Z")

</div>

Hello everyone!  
I need help for converting a string data to integer value.  
I have an 'Hours' column which consist of numeric data but kibana is reading as string as a result when i try to sort the axis it does not sort properly.

Can someone please tell me steps to convert string to integer?

I use Kibana 7.13.2.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [July 6, 2021, 9:20pm UTC](https://discuss.elastic.co/t/convert-string-to-integer/277915/2 "2021-07-06T21:20:51Z")

</div>

Can you share the mapping for your index, particularly the `Hours` field?

---

<div class="post-metadata">

**Author:** ![ANKITA\_SAHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankita_saha/32/91152_2.png) [@ANKITA\_SAHA](https://discuss.elastic.co/u/ANKITA_SAHA)\
**Post date:** [July 7, 2021, 7:26am UTC](https://discuss.elastic.co/t/convert-string-to-integer/277915/3 "2021-07-07T07:26:45Z")

</div>

```auto
"hour": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

```

The problem is it is reading the heading 'hour' as a result it converts entire field to text.  
I created ingest pipeline to convert str to int and reindex but unfortunately it always gives error like "type" : "number\_format\_exception", "reason" : "for input string: "hour""

---

<div class="post-metadata">

**Author:** ![ANKITA\_SAHA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankita_saha/32/91152_2.png) [@ANKITA\_SAHA](https://discuss.elastic.co/u/ANKITA_SAHA)\
**Post date:** [July 9, 2021, 4:31pm UTC](https://discuss.elastic.co/t/convert-string-to-integer/277915/4 "2021-07-09T16:31:07Z")

</div>

> [@Fix x-axis in Kibana 7.13.2](https://discuss.elastic.co/t/fix-x-axis-in-kibana-7-13-2/277918/9):
>
> Check out runtime fields in the Lens UI instead of stack management (it's newer as of 7.13) - [Lens | Kibana Guide [7.13] | Elastic](https://www.elastic.co/guide/en/kibana/current/lens.html#add-fields-in-lens)
> 
> You can add a script that converts the field to the appropriate data type. Really, though, if this works for you it's more performant to index the appropriate type up front (runtime fields are slower than indexed fields).
> 
> Here's an example that does the opposite of what you're trying to do. The example uses painless which exposes a lot of useful java APIs.
> 
> ```auto
> Long input = doc['event.duration'].value;
> String output = Objects.toString(input);
> 
> emit(output);
> 
> ```

Thank you @ghudgins for the solution 😀

---

<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 6, 2021, 4:31pm UTC](https://discuss.elastic.co/t/convert-string-to-integer/277915/5 "2021-08-06T16:31:24Z")

</div>

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