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


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 => [""]
                           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=>["", "", ""

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?


if not [tags]

work for you?

no it does not!

I finally found one way:

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

it check for not null and if array is empty


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