# How to tell if tags is empty or does not exists?

**URL:** https://discuss.elastic.co/t/how-to-tell-if-tags-is-empty-or-does-not-exists/207168
**Category:** Logstash
**Created:** [November 8, 2019, 8:26pm UTC](https://discuss.elastic.co/t/how-to-tell-if-tags-is-empty-or-does-not-exists/207168 "2019-11-08T20:26:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mtudisco](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mtudisco](https://discuss.elastic.co/u/mtudisco)
#### Post date: [November 8, 2019, 8:26pm UTC](https://discuss.elastic.co/t/how-to-tell-if-tags-is-empty-or-does-not-exists/207168/1 "2019-11-08T20:26:36Z")

</div>

Hi,

I want to be able to check if tags field is empty or if it does not exists in order to send the logstash output to different indexes. I'm using logstash 7.3

```
output {
  stdout { codec => rubydebug }
  if [tags] == [] {
     elasticsearch { hosts => ["https://192.168.90.119:9200"]
                           cacert => '/etc/logstash/config/certs/ca.crt'
                           user => 'logstash_writer'
                           password => '${lsw_pwd}'
                           index => "%{[type]}-%{type2}-%{+YYYY.MM.dd}"
                }
  }
}

```

however logstash does not start with the following error:

> `[ERROR][logstash.agent] Failed to execute action {:id=\>:main, :action\_type=\>LogStash::ConvergeResult::FailedAction, :message=\>"Failed to parse right-hand side of conditional [str]pipeline:599:6:`\n[tags] == []\n`", :backtrace=\>["org.logstash.config.ir.expression.BinaryBooleanExpression.ensureNotNull(org/logstash/config/ir/expression/BinaryBooleanExpression.java:54)", "org.logstash.config.ir.expression.BinaryBooleanExpression.(org/logstash/config/ir/expression/BinaryBooleanExpression.java:34)", "org.logstash.config.ir.expression.binary.Eq.(org/logstash/config/ir/expression/binary/Eq.java:9)"

I also tried

```
if [tags] =~ /.+/ {
   #do something
}

```

it starts but never gets into the do something even when there are tags.  
Can anyone suggest something?

---

<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: [November 8, 2019, 9:09pm UTC](https://discuss.elastic.co/t/how-to-tell-if-tags-is-empty-or-does-not-exists/207168/2 "2019-11-08T21:09:46Z")

</div>

Does

```
if not [tags]

```

work for you?

---

<div class="post-metadata">

### Author: ![mtudisco](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mtudisco](https://discuss.elastic.co/u/mtudisco)
#### Post date: [November 8, 2019, 9:18pm UTC](https://discuss.elastic.co/t/how-to-tell-if-tags-is-empty-or-does-not-exists/207168/3 "2019-11-08T21:18:32Z")

</div>

no it does not!

I finally found one way:

```
    if [tags] and !([tags][0]) {

```

it check for not null and if array is empty

reference: [https://stackoverflow.com/questions/49047453/remove-array-field-if-empty/49051338](https://stackoverflow.com/questions/49047453/remove-array-field-if-empty/49051338)

---

<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 6, 2019, 9:18pm UTC](https://discuss.elastic.co/t/how-to-tell-if-tags-is-empty-or-does-not-exists/207168/4 "2019-12-06T21:18:44Z")

</div>

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