# Check if sub-field exists

**URL:** <https://discuss.elastic.co/t/check-if-sub-field-exists/66046>\
**Category:** Logstash\
**Created:** [November 15, 2016, 3:31am UTC](https://discuss.elastic.co/t/check-if-sub-field-exists/66046 "2016-11-15T03:31:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gringo](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@gringo](https://discuss.elastic.co/u/gringo)\
**Post date:** [November 15, 2016, 3:31am UTC](https://discuss.elastic.co/t/check-if-sub-field-exists/66046/1 "2016-11-15T03:31:30Z")

</div>

I need an if else statement to check if a sub field exists. I want ed to know if a sub-field "city\_name" exists in main field dst\_geoip. Below is what I'm trying to do

if ![dst\_geoip][city\_name] {mutate{add\_field =\> { "[dst\_geoip][city\_name]" =\> "nil" }}}

Anyone knows the right way to write the if else statement

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 15, 2016, 6:45am UTC](https://discuss.elastic.co/t/check-if-sub-field-exists/66046/2 "2016-11-15T06:45:31Z")

</div>

What you've written should work. What happens? And are you sure you want to set the field to a literal "nil"?

---

<div class="post-metadata">

**Author:** ![gringo](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@gringo](https://discuss.elastic.co/u/gringo)\
**Post date:** [November 15, 2016, 7:08am UTC](https://discuss.elastic.co/t/check-if-sub-field-exists/66046/3 "2016-11-15T07:08:20Z")

</div>

I intend to send these into another application when require all fields to be present despite certain fields are non-existence in current set of logs.

---

<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 13, 2016, 7:08am UTC](https://discuss.elastic.co/t/check-if-sub-field-exists/66046/4 "2016-12-13T07:08:34Z")

</div>

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