# How to increment a field with JSON input?

**URL:** <https://discuss.elastic.co/t/how-to-increment-a-field-with-json-input/151230>\
**Category:** Kibana\
**Created:** [October 5, 2018, 2:55pm UTC](https://discuss.elastic.co/t/how-to-increment-a-field-with-json-input/151230 "2018-10-05T14:55:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krone](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Krone](https://discuss.elastic.co/u/Krone)\
**Post date:** [October 5, 2018, 2:55pm UTC](https://discuss.elastic.co/t/how-to-increment-a-field-with-json-input/151230/1 "2018-10-05T14:55:37Z")

</div>

Hello all. I'm having some trouble with the JSON input field , i have read all the documentation i can find yet this script does not work either syntactically , runtime error or compilation error  
{

```
"script" : 
{
"source": """
    int i = 0;
    while(doc['id'])
    {
	    doc['id'].value - doc['id'].value + i;
	    i++;
    }
	 """
}

```

}

Basically what i want is to increment the last field of this data table by 1 for every row

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/4/246cda59f9c3f970d88c2dfe62dfcd8f104496aa.png)

Thank you

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [October 10, 2018, 10:01am UTC](https://discuss.elastic.co/t/how-to-increment-a-field-with-json-input/151230/2 "2018-10-10T10:01:22Z")

</div>

Advanced JSON doesn't allow you to add inline scripts. You could create a scripted field with the code from inside your script and see if that fits your needs.

---

<div class="post-metadata">

**Author:** ![Krone](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Krone](https://discuss.elastic.co/u/Krone)\
**Post date:** [October 12, 2018, 8:56am UTC](https://discuss.elastic.co/t/how-to-increment-a-field-with-json-input/151230/3 "2018-10-12T08:56:16Z")

</div>

Thank you for your insight. It worked with the scripted fields. 🙂

---

<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 9, 2018, 9:08am UTC](https://discuss.elastic.co/t/how-to-increment-a-field-with-json-input/151230/4 "2018-11-09T09:08:42Z")

</div>

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