# Conditional IF and ELIF in set processor

**URL:** <https://discuss.elastic.co/t/conditional-if-and-elif-in-set-processor/316123>\
**Category:** Elasticsearch\
**Tags:** ingest-pipeline\
**Created:** [October 8, 2022, 10:00am UTC](https://discuss.elastic.co/t/conditional-if-and-elif-in-set-processor/316123 "2022-10-08T10:00:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomx1](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@tomx1](https://discuss.elastic.co/u/tomx1)\
**Post date:** [October 8, 2022, 10:00am UTC](https://discuss.elastic.co/t/conditional-if-and-elif-in-set-processor/316123/1 "2022-10-08T10:00:37Z")

</div>

I'm setting the value of a field named "customer" depending on the value of field "destination.ip" via ingest pipeline. Currently I'm using two independent Set processors via ingest pipeline for IPv4 and IPv6. But it would be nicer to have it all together. So what I have now looks like that:

```auto
ctx['netflow'].containsKey('destination_ipv4_address') && ctx?.netflow?.destination_ipv4_address =~ /^(192.168.0.(1|2|3|4|5)|127.22.3.(1|2|3|4|5))$/

```

How could I have this condition all in one? I mean something like that:

```auto
ctx['netflow'].containsKey('destination_ipv4_address') && ctx?.netflow?.destination_ipv4_address =~ /^(192.168.0.(1|2|3|4|5)|127.22.3.(1|2|3|4|5))$/
OR
ctx['netflow'].containsKey('destination_ipv6_address') && ctx?.netflow?.destination_ipv6_address =~ /^(2a02.68.0.(1|2|3|4|5)|2a08.2.3.(1|2|3|4|5))$/

```

That means, that I could make one Set processor for each customer instead of making two Set processors for each customer (one for ipv4 and one for ipv6)

---

<div class="post-metadata">

**Author:** ![tomx1](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@tomx1](https://discuss.elastic.co/u/tomx1)\
**Post date:** [October 8, 2022, 5:06pm UTC](https://discuss.elastic.co/t/conditional-if-and-elif-in-set-processor/316123/2 "2022-10-08T17:06:53Z")

</div>

I managed to get it done via script proessor and the following code:

```auto
if( ctx?.netflow?.destination_ipv4_address =~ /^(8.8.8.8|9.9.9.9)$/ ) {
    ctx.customer = ["account" : "customer1"] ;
} else if ( ctx?.netflow?.destination_ipv6_address =~ /^(2002:37a:1bc::13|2001:37b:50d8::9)$/ ) {
    ctx.customer = ["account" : "customer1"] ;
}

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 8, 2022, 5:34pm UTC](https://discuss.elastic.co/t/conditional-if-and-elif-in-set-processor/316123/3 "2022-10-08T17:34:01Z")

</div>

Beat me to it!

The processors only have a single if / conditional statement. I was about to say you should do a script but you figured it out. Awesome and thanks for posting your result. It helps other people

---

<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 5, 2022, 5:34pm UTC](https://discuss.elastic.co/t/conditional-if-and-elif-in-set-processor/316123/4 "2022-11-05T17:34:30Z")

</div>

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