# How to create a scripted field with multiple conditions

**URL:** <https://discuss.elastic.co/t/how-to-create-a-scripted-field-with-multiple-conditions/78718>\
**Category:** Kibana\
**Created:** [March 15, 2017, 2:28pm UTC](https://discuss.elastic.co/t/how-to-create-a-scripted-field-with-multiple-conditions/78718 "2017-03-15T14:28:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [March 15, 2017, 2:28pm UTC](https://discuss.elastic.co/t/how-to-create-a-scripted-field-with-multiple-conditions/78718/1 "2017-03-15T14:28:13Z")

</div>

HI,

I have created a scripted field `sc1` in kibana like;

```
doc['error.keyword'].value == 'error1' ? 0 : 1

```

this makes `sc1` 0 if the content is `error1` and 0 if content is not `error1`. What I want is, I want `sc1` to be 0, if the content is either `error1` or `error2`. How can I do this?

Thanks in advance..

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [March 16, 2017, 12:00pm UTC](https://discuss.elastic.co/t/how-to-create-a-scripted-field-with-multiple-conditions/78718/2 "2017-03-16T12:00:43Z")

</div>

@elasticcloud Painless supports the `||` (OR) operator you can use to do the following:

```auto
doc['error.keyword'].value == 'error1' || doc['error.keyword'].value == 'error2' ? 0 : 1

```

Or you can use the `contains` method to do the following:

```auto
['error1', 'error2'].contains(doc['error.keyword'].value) ? 0 : 1

```

---

<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:** [April 13, 2017, 12:01pm UTC](https://discuss.elastic.co/t/how-to-create-a-scripted-field-with-multiple-conditions/78718/3 "2017-04-13T12:01:13Z")

</div>

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