# Check if a field exists

**URL:** <https://discuss.elastic.co/t/check-if-a-field-exists/284545>\
**Category:** Logstash\
**Created:** [September 18, 2021, 2:24pm UTC](https://discuss.elastic.co/t/check-if-a-field-exists/284545 "2021-09-18T14:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeoiioze](https://avatars.discourse-cdn.com/v4/letter/z/d07c76/32.png) [@zeoiioze](https://discuss.elastic.co/u/zeoiioze)\
**Post date:** [September 18, 2021, 2:24pm UTC](https://discuss.elastic.co/t/check-if-a-field-exists/284545/1 "2021-09-18T14:24:27Z")

</div>

I'm using nested fields and a field name in the nested field name, as you can see below (example) :

```auto

[doc][vegetables][%{[tmp_data][vegetable_name]}][number]

```

The field above is getting created, but now, I want in another filter (i'm updating existing documents) to check if the field exists. I tried to do things like :

- `if ([doc][vegetables][%{[tmp_data][vegetable_name]}][number]) {`

- `if "[doc][vegetables][%{[tmp_data][vegetable_name]}][number]" {`

- `if [doc][vegetables]["%{[tmp_data][vegetable_name]}"][number] {`

What's the correct syntax ?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 18, 2021, 4:25pm UTC](https://discuss.elastic.co/t/check-if-a-field-exists/284545/2 "2021-09-18T16:25:50Z")

</div>

> [@zeoiioze](#):
>
> What's the correct syntax ?

There isn't one. You [cannot](https://discuss.elastic.co/t/logstash-if-condition/250689) use a sprintf reference in a conditional.

---

<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:** [October 16, 2021, 4:26pm UTC](https://discuss.elastic.co/t/check-if-a-field-exists/284545/3 "2021-10-16T16:26:16Z")

</div>

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