# Can we send logs to different outputs depending on filename they come from?

**URL:** https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815
**Category:** Logstash
**Created:** [July 30, 2019, 3:58am UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815 "2019-07-30T03:58:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![RITZ\_VERMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritz_verma/32/46899_2.png) [@RITZ\_VERMA](https://discuss.elastic.co/u/RITZ_VERMA)
#### Post date: [July 30, 2019, 3:58am UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/1 "2019-07-30T03:58:36Z")

</div>

in logstash i am trying to send logs from different files to different elasticsearch depending on their filename. is this possible?

---

<div class="post-metadata">

### Author: ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)
#### Post date: [July 30, 2019, 12:20pm UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/2 "2019-07-30T12:20:33Z")

</div>

Sure

```
output {
    if <your logic here> {
      elasticsearch {..first target..}
    } else {
      elasticsearch {..other target..}
    }
}
```

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [July 30, 2019, 2:14pm UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/3 "2019-07-30T14:14:28Z")

</div>

@RITZ_VERMA

Do you mean a different cluster or a different index in the same cluster?

---

<div class="post-metadata">

### Author: ![RITZ\_VERMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritz_verma/32/46899_2.png) [@RITZ\_VERMA](https://discuss.elastic.co/u/RITZ_VERMA)
#### Post date: [July 30, 2019, 5:50pm UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/4 "2019-07-30T17:50:23Z")

</div>

In the same elastic cluster but on different indexes.i figured it out thanks

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [July 31, 2019, 8:22am UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/5 "2019-07-31T08:22:08Z")

</div>

Did you figure out that the [**`index`** setting can be interpolated from values](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-index) held in the event itself?

This eliminates the logic in the output section.

From this:

```auto
    if [es_sub_index_] == "metrics" {
      elasticsearch { index => "app_metrics" }
    } else {
      elasticsearch { index => "app_logs" }
    }

```

to:

```auto
     elasticsearch { index => "app_%{es_sub_index}" ... }

```

You will still need some logic in the filter section to add a value to a field called `es_sub_index` but using interpolation means that the communication with ES will not be broken into smaller chunks that are less efficient. The full batch will be sent to ES in one REST call and the body contains the divisions. In English, something like "In this index put these docs then in this other index put these docs...".

Using logic in the output section will mean a separate REST call per conditional block and they are not parallelised.

---

<div class="post-metadata">

### Author: ![RITZ\_VERMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritz_verma/32/46899_2.png) [@RITZ\_VERMA](https://discuss.elastic.co/u/RITZ_VERMA)
#### Post date: [August 8, 2019, 11:44pm UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/6 "2019-08-08T23:44:39Z")

</div>

this make things a lot easier  
thanks @guyboertje and apologies for late reply

---

<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: [September 5, 2019, 11:44pm UTC](https://discuss.elastic.co/t/can-we-send-logs-to-different-outputs-depending-on-filename-they-come-from/192815/7 "2019-09-05T23:44:42Z")

</div>

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