# Condition to check if two or three fields exist

**URL:** <https://discuss.elastic.co/t/condition-to-check-if-two-or-three-fields-exist/151577>\
**Category:** Logstash\
**Created:** [October 9, 2018, 8:53am UTC](https://discuss.elastic.co/t/condition-to-check-if-two-or-three-fields-exist/151577 "2018-10-09T08:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pastechecker](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pastechecker](https://discuss.elastic.co/u/pastechecker)\
**Post date:** [October 9, 2018, 8:53am UTC](https://discuss.elastic.co/t/condition-to-check-if-two-or-three-fields-exist/151577/1 "2018-10-09T08:53:38Z")

</div>

Hello,  
I have the following condition in the logstash filter section:

> if [MD5] {  
> mutate { add\_field =\> { "md5\_field" =\> "MD5 Hash is: %{MD5}" for %{url} and %{location}}}  
> }

It is not solid enough, because if url or location json field does not exist it will print into the field %{url} or %{location}.  
Is there a way to check for the existence of those three fields in one if condition?

For example:

> if [MD5] and [url] and [location] {  
> mutate { add\_field =\> { "md5\_field" =\> "MD5 Hash is: %{MD5}" for %{url} and %{location}}}  
> }

Thanks.

---

<div class="post-metadata">

**Author:** ![pastechecker](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pastechecker](https://discuss.elastic.co/u/pastechecker)\
**Post date:** [October 9, 2018, 11:24am UTC](https://discuss.elastic.co/t/condition-to-check-if-two-or-three-fields-exist/151577/2 "2018-10-09T11:24:53Z")

</div>

the workaround I found is:

if [MD5]{  
if [url]{  
your\_action  
}  
}

---

<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 6, 2018, 11:24am UTC](https://discuss.elastic.co/t/condition-to-check-if-two-or-three-fields-exist/151577/3 "2018-11-06T11:24:57Z")

</div>

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