# Keep one logstash conf file rather having multiple logstash conf file!

**URL:** https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436
**Category:** Logstash
**Created:** [February 7, 2019, 11:31am UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436 "2019-02-07T11:31:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![inandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inandi/32/40801_2.png) [@inandi](https://discuss.elastic.co/u/inandi)
#### Post date: [February 7, 2019, 11:31am UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436/1 "2019-02-07T11:31:25Z")

</div>

Suppose I have two sets of data i.e. user & products. I have created two different indexes for them on ES. Now I want to use **one logstash** conf file that will have some condition to differentiate the data and send them to their related index ie users data to user index and product data to product index.

is it even possible or I am daydreaming!!!

Cheers @inandi

---

<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: [February 7, 2019, 2:05pm UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436/2 "2019-02-07T14:05:58Z")

</div>

Yes, you can use conditionals in the output section. Like this

```
output {
    if (some condition) {
        elasticsearch {
             first configuration
        }
    } else {
        elasticsearch {
             second configuration
        }
    }
}

```

Or, if the only difference is the index name, and the name of the index is based on a field in the event then you can use a sprintf reference.

```
output {
    elasticsearch {
        index => "%{someField}-%{+YYYY.MM}"
    }
}
```

---

<div class="post-metadata">

### Author: ![inandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inandi/32/40801_2.png) [@inandi](https://discuss.elastic.co/u/inandi)
#### Post date: [February 7, 2019, 3:44pm UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436/3 "2019-02-07T15:44:35Z")

</div>

thanks, @Badger for your reply. I am posting my sample logstash conf file

```
input {
  file {
    path => "/var/www/html/elastic/user_data.json"
    start_position => "beginning"
    sincedb_path => "/dev/null"
    codec => "json"        
  }
}

filter { }

output {
    elasticsearch {
      hosts => ["http://192.168.0.1:9200/"] 
      index => "user_index"
      document_id => "%{userid}"
      template =>"/var/www/html/elastic/user_template.json"
      template_name=>"datauser"
      template_overwrite => true
  }
} 

```

now suppose I have another JSON file which contains product data and i want to insert that into product\_index, so How to write this logstash file?

Thanks @inandi

---

<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: [February 7, 2019, 3:56pm UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436/4 "2019-02-07T15:56:46Z")

</div>

If you want to process both files in the same logstash configuration then you can add a second file input. Then in the filter section test the path field on the event

```
if [path] =~ "user_data.json" {
    mutate { add_field => { "filetype" => "user" } }
} else {
    mutate { add_field => { "filetype" => "product" } }
}

```

Then you can use a conditional in the output section

```
output {
    if [filetype] == "user" {
        elasticsearch {
             first configuration
        }
    } else {
        elasticsearch {
             second configuration
        }
    }
}
```

---

<div class="post-metadata">

### Author: ![inandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inandi/32/40801_2.png) [@inandi](https://discuss.elastic.co/u/inandi)
#### Post date: [February 7, 2019, 4:22pm UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436/5 "2019-02-07T16:22:49Z")

</div>

exactly I wanted something like this. Cheers @Badger 🙂

---

<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: [March 7, 2019, 4:23pm UTC](https://discuss.elastic.co/t/keep-one-logstash-conf-file-rather-having-multiple-logstash-conf-file/167436/6 "2019-03-07T16:23:02Z")

</div>

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