# How to create a new script field to group values

**URL:** <https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290>\
**Category:** Kibana\
**Created:** [November 27, 2018, 8:18am UTC](https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290 "2018-11-27T08:18:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinay.rao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinay.rao/32/49894_2.png) [@vinay.rao](https://discuss.elastic.co/u/vinay.rao)\
**Post date:** [November 27, 2018, 8:18am UTC](https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290/1 "2018-11-27T08:18:19Z")

</div>

Dear All,

Am trying to create a new scripted field and need to group values. Please help me to write the script to get the values

if ( Status='Closed' or Status="Resolved' then 'Closed' else 'Pending').

How to write the same in Kibana script to create new field.

Regards,  
Vinay N

---

<div class="post-metadata">

**Author:** ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)\
**Post date:** [November 27, 2018, 1:23pm UTC](https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290/2 "2018-11-27T13:23:47Z")

</div>

Hi @vinay.rao,

You'll want something like this:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/a/6a58ba33e0751ffb59cd67bf68ecaf5a149c2b02.jpeg)

```auto
if (doc['status.keyword'].value == "Resolved" || doc['status.keyword'].value == "Closed") {
    return "Closed";
  }

return "Pending";

```

---

<div class="post-metadata">

**Author:** ![vinay.rao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinay.rao/32/49894_2.png) [@vinay.rao](https://discuss.elastic.co/u/vinay.rao)\
**Post date:** [November 28, 2018, 7:45am UTC](https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290/3 "2018-11-28T07:45:33Z")

</div>

@Larry_Gregory : Thanks a lot for your Workaround. I have used the Script which is suggested by you. But am not able to get the output field in my index. Please find the attachment of the error which am facing. Appreciate your response to find out the solution.

Regards,  
Vinay N

 ![Error](https://us1.discourse-cdn.com/elastic/original/3X/8/3/8306022e7d5f183cdc9d4376114bd066f1600489.jpeg)

---

<div class="post-metadata">

**Author:** ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)\
**Post date:** [November 28, 2018, 12:44pm UTC](https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290/4 "2018-11-28T12:44:17Z")

</div>

Is `result.state` a `keyword` or `text` field? It should be a `keyword` field for this script to work correctly

---

<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:** [December 26, 2018, 12:44pm UTC](https://discuss.elastic.co/t/how-to-create-a-new-script-field-to-group-values/158290/5 "2018-12-26T12:44:19Z")

</div>

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