Logstash - IF / ELSE with document_id

Can anyone help me identify why the setup below does not work with document_id.

Context of my configuration, I am importing data from a relational database so I need the sync id.

output {
  stdout {
    codec => rubydebug
  }
  if "jdbc" in [tags] {
    elasticsearch {
      hosts => [ "http://elasticsearch:9200" ]
      user => elastic
      password => "${elastic_password}"
      index => "basa-banklink-%{type}"
      document_id => "%{id_sync}"
      manage_template => true
      template => "/etc/logstash/template-index/basa/banklink/basa-banklink.json"
      template_name => "basa-banklink"
      template_overwrite => "true"
    }
  }
  else if "beats" in [tags] {
    elasticsearch {
      hosts => [ "http://elasticsearch:9200" ]
      user => elastic
      password => "${elastic_password}"
      index => "basa-banklink-%{type}"
    }
  }
  else {
    elasticsearch {
      hosts => [ "http://elasticsearch:9200" ]
      user => elastic
      password => "${elastic_password}"
      index => "basa-banklink-%{type}"
    }
  }
}

Output from stdout to above configuration:

{
        "cendsc" => "TEXTO 000",
    "@timestamp" => 2019-01-22T10:28:09.239Z,
          "type" => "cen",
       "id_sync" => 330,
        "datref" => nil,
        "cencod" => 330,
      "@version" => "1"
}

When I use the configuration below, it works perfectly:

output {
	stdout {
	  codec => rubydebug
	}
	elasticsearch {
	  hosts => [ "http://elasticsearch:9200" ]
	  user => elastic
	  password => "${elastic_password}"
	  index => "basa-banklink-%{type}"
	  document_id => "%{id_sync}"
	  manage_template => true
	  template => "/etc/logstash/template-index/basa/banklink/basa-banklink.json"
	  template_name => "basa-banklink"
	  template_overwrite => "true"
	}
}

It doesn't look like you have any tags set and the default output does not specify any document_id.

Do I have to specify a tag with the same name as the json tag?

Because I did not really define a tag with the same name because I thought the json tag would be enough.

For example:

input {
  beats { <== Would not it be a tag ?
  ...
  }
  file { <== Would not it be a tag ?
  ...
  }
  jdbc { <== Would not it be a tag ?
  ...
  }
}

The plugin names are not tags. You can however use the tags parameter to add tags per input plugin.

Thank you very much @Christian_Dahlqvist .

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