# Logstash - IF / ELSE with document\_id

**URL:** <https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214>\
**Category:** Logstash\
**Created:** [January 22, 2019, 10:36am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214 "2019-01-22T10:36:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 22, 2019, 10:36am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214/1 "2019-01-22T10:36:16Z")

</div>

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"
	}
}
```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 22, 2019, 11:03am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214/2 "2019-01-22T11:03:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 22, 2019, 11:09am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214/3 "2019-01-22T11:09:32Z")

</div>

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 ?
  ...
  }
}
```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 22, 2019, 11:13am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214/4 "2019-01-22T11:13:42Z")

</div>

The plugin names are not tags. You can however use the [tags parameter](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#plugins-inputs-file-tags) to add tags per input plugin.

---

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 22, 2019, 11:18am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214/5 "2019-01-22T11:18:11Z")

</div>

Thank you very much @Christian_Dahlqvist .

---

<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:** [February 19, 2019, 11:18am UTC](https://discuss.elastic.co/t/logstash-if-else-with-document-id/165214/6 "2019-02-19T11:18:28Z")

</div>

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