# If Array element not present

**URL:** <https://discuss.elastic.co/t/if-array-element-not-present/179938>\
**Category:** Logstash\
**Created:** [May 7, 2019, 10:51am UTC](https://discuss.elastic.co/t/if-array-element-not-present/179938 "2019-05-07T10:51:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghost3h](https://avatars.discourse-cdn.com/v4/letter/g/bc8723/32.png) [@ghost3h](https://discuss.elastic.co/u/ghost3h)\
**Post date:** [May 7, 2019, 10:51am UTC](https://discuss.elastic.co/t/if-array-element-not-present/179938/1 "2019-05-07T10:51:23Z")

</div>

Is there a way to only set a field to an array element when its populated?

```
     split => { "HOSTALIAS" => ", " }
      add_field => {
                "ci_alias" => "%{[HOSTALIAS][0]}"
                "blueprint-id" => "%{[HOSTALIAS][1]}"
                "instance-id" => "%{[HOSTALIAS][2]}"
	        "vm-location" => "%{[HOSTALIAS][3]}"

```

This works fine when all elemnts of the array are populated, but in the instance that [3] isnt sent, I get

> "vm-location" =\> "%{[HOSTALIAS][3]}",

Is there a way to check this, without doing a lot of 'if' statements to check?

---

<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:** [May 7, 2019, 3:20pm UTC](https://discuss.elastic.co/t/if-array-element-not-present/179938/2 "2019-05-07T15:20:47Z")

</div>

> [@ghost3h](#):
>
> Is there a way to check this, without doing a lot of 'if' statements to check?

Not that I can think of.

---

<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:** [June 4, 2019, 3:20pm UTC](https://discuss.elastic.co/t/if-array-element-not-present/179938/3 "2019-06-04T15:20:55Z")

</div>

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