# Conditional match for numeric type in list?

**URL:** <https://discuss.elastic.co/t/conditional-match-for-numeric-type-in-list/130447>\
**Category:** Logstash\
**Created:** [May 3, 2018, 11:50am UTC](https://discuss.elastic.co/t/conditional-match-for-numeric-type-in-list/130447 "2018-05-03T11:50:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PandKing](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@PandKing](https://discuss.elastic.co/u/PandKing)\
**Post date:** [May 3, 2018, 11:50am UTC](https://discuss.elastic.co/t/conditional-match-for-numeric-type-in-list/130447/1 "2018-05-03T11:50:13Z")

</div>

Hi, Please help,

I have been struggling with this for a few days.

How can I match a numeric field against a long list of numbers?  
Would it be best to use grok or ruby?

I can do it for one but there must be a more elegant way than this.  
My match list is non linear so I cannot use greater than or any of the other operators.

if [filed] == 9991 {  
...  
} else if [field] == 5678 {  
...  
}  
} else if [field] == 91011 {  
...  
}  
} else if [field] == 121314 {  
...  
} else {  
...  
}

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [May 3, 2018, 12:59pm UTC](https://discuss.elastic.co/t/conditional-match-for-numeric-type-in-list/130447/2 "2018-05-03T12:59:28Z")

</div>

Try this

```auto
if [field] in [9991, 5678, 91011, 121314] {
    ...
}
else {
    ...
}
```

Custom Ruby code is also an option, and could be a better alternative depending on what you want to do when the value matches. If you are going to use Ruby inside the _if_ branch to manipulate numbers, it may make sense to also have the actual check inside the Ruby block.

---

<div class="post-metadata">

**Author:** ![PandKing](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@PandKing](https://discuss.elastic.co/u/PandKing)\
**Post date:** [May 3, 2018, 1:36pm UTC](https://discuss.elastic.co/t/conditional-match-for-numeric-type-in-list/130447/3 "2018-05-03T13:36:46Z")

</div>

Thank you PAZ!  
That seems to be working well.

Thought I tried that but must have been  
if [field] == [##,##,##]

---

<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:** [May 31, 2018, 1:36pm UTC](https://discuss.elastic.co/t/conditional-match-for-numeric-type-in-list/130447/4 "2018-05-31T13:36:52Z")

</div>

Closed on May 31, 2018, 1:36pm UTC

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