# If \[@metadata\]\[field\] {} doesnot work

**URL:** https://discuss.elastic.co/t/if-metadata-field-doesnot-work/146681
**Category:** Logstash
**Created:** [August 30, 2018, 10:49am UTC](https://discuss.elastic.co/t/if-metadata-field-doesnot-work/146681 "2018-08-30T10:49:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vemula.pranavi](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vemula.pranavi](https://discuss.elastic.co/u/vemula.pranavi)
#### Post date: [August 30, 2018, 10:49am UTC](https://discuss.elastic.co/t/if-metadata-field-doesnot-work/146681/1 "2018-08-30T10:49:17Z")

</div>

I'm trying to give syntax like 'if [@metadata][field] exists then do this' in output  
output{  
if [@metadata][field] {  
elasticsearch {  
hosts =\> ["[http://localhost:9200](http://localhost:9200)"]  
index =\> "%{[@metadata][field]}"  
}  
}  
}  
I used two config files. One config file , I created input{} filter{} output{}(like above) , other file only filter{} which adds a field [@metadata][field] like  
filter{  
mutate {  
add\_field =\> { "[@metadata][index\_name]" =\> "abc" }  
}  
}

The index gets created in elasticsearch, when I comment the if statement in the output, but when I remove, it does not get created.  
How to make command enter into if 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: [August 30, 2018, 11:12am UTC](https://discuss.elastic.co/t/if-metadata-field-doesnot-work/146681/2 "2018-08-30T11:12:18Z")

</div>

Please show the exact configuration you're using so that we can try to reproduce the issue. Which Logstash version?

---

<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: [August 30, 2018, 12:03pm UTC](https://discuss.elastic.co/t/if-metadata-field-doesnot-work/146681/4 "2018-08-30T12:03:16Z")

</div>

I suggest you add a `stdout { codec => rubydebug { metadata => true } }` output to see what metadata fields you _really_ have.

---

<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: [September 27, 2018, 12:03pm UTC](https://discuss.elastic.co/t/if-metadata-field-doesnot-work/146681/5 "2018-09-27T12:03:17Z")

</div>

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