# How create 2 different indexs with same file source?

**URL:** <https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594>\
**Category:** Logstash\
**Created:** [September 30, 2022, 3:56pm UTC](https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594 "2022-09-30T15:56:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolas1306](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikolas1306/32/111507_2.png) [@Nikolas1306](https://discuss.elastic.co/u/Nikolas1306)\
**Post date:** [September 30, 2022, 3:56pm UTC](https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594/1 "2022-09-30T15:56:25Z")

</div>

this is my conf file and it's ok i've created an index with only errors match  
but now it's possible create a second indexs with file warning or custom?

```auto
code => "event.cancel if not event.get('message').include? 'WARN' " 
.....

elasticsearch {
			hosts => ["elasticsearch:9200"]
			index => "warn" ?????? other index file??? is possible
		}

```

my file logstash.conf

```auto
input {
  file {
    path => [ "/logstash_dir/P1/*.*",
                     "/logstash_dir/P2/*.*" ]
      start_position => "beginning"
  }
}

filter {
  
   ruby {
    
             code => "event.cancel if not event.get('message').include? 'ERROR' " 
       
         }
}

output {

		elasticsearch {
			hosts => ["elasticsearch:9200"]
			index => "errors"
		}
		stdout { codec => rubydebug }	
	
}

```

---

<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:** [September 30, 2022, 4:25pm UTC](https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594/2 "2022-09-30T16:25:34Z")

</div>

You could remove the ruby filter and do something like

> [@Nikolas1306](#):
>
> ```auto
> output {
> if "ERROR" in [message] {
> elasticsearch {
> hosts => ["elasticsearch:9200"]
> index => "errors"
> }
> } else {
> elasticsearch {
> hosts => ["elasticsearch:9200"]
> index => "other"
> }
> }
> stdout { codec => rubydebug }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Nikolas1306](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikolas1306/32/111507_2.png) [@Nikolas1306](https://discuss.elastic.co/u/Nikolas1306)\
**Post date:** [September 30, 2022, 4:47pm UTC](https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594/3 "2022-09-30T16:47:11Z")

</div>

hello very good but is possible use (ruby or other sintax ) for personalize other type of index?

example

1. if I would like to create separate indexes based on the path of origin
2. if I would like to create separate indexes based on advanced text contains

---

<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:** [September 30, 2022, 5:07pm UTC](https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594/4 "2022-09-30T17:07:56Z")

</div>

You can use [conditionals](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#conditionals) with multiple branches. See [this](https://discuss.elastic.co/t/multiple-pipelines-or-tags-or-if-or-else-if/173974/2) thread.

Splitting your data into a large number of small indexes is not a good practice because a large number of indexes/shards is more costly than a single index with tagged events.

---

<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:** [October 28, 2022, 5:08pm UTC](https://discuss.elastic.co/t/how-create-2-different-indexs-with-same-file-source/315594/5 "2022-10-28T17:08:21Z")

</div>

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