# How to Seperate docs in Logstash to different ES index

**URL:** <https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249>\
**Category:** Logstash\
**Created:** [May 26, 2017, 11:45am UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249 "2017-05-26T11:45:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasvanth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yasvanth/32/45818_2.png) [@yasvanth](https://discuss.elastic.co/u/yasvanth)\
**Post date:** [May 26, 2017, 11:45am UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249/1 "2017-05-26T11:45:41Z")

</div>

Hi All,

I am inserting data to logstash(collector) via nxlog(sender) to single port. The logs are already parsed on nxlog side from .xml to json , these parsed doc contains logs from different application such as apache, tomcat etc. I have field named as Log\_type to apache or tomcat.

So I want to set a statement to check if the Log\_type = apache send to Index-Apache , If Log\_type = tomcat send to Index\_tomcat.

My Logstash conf is:

input {  
tcp {  
codec =\> json\_lines{ charset =\> CP1252 }  
port =\> 9514  
tags =\>["tcpjson"]  
}  
}

output {  
if "Log\_Type" == [apache\_Logs} {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
action =\> 'index'  
index =\> 'apache-%{+YYYY.MM.dd}'  
}  
if "Log\_Type" == [tomcat\_Logs} {  
elasticsearch {  
hosts =\> ["tomcat:9200"]  
action =\> 'index'  
index =\> 'tomcat-%{+YYYY.MM.dd}'  
}  
}

I am not using filter statement since the logs are parsed with field names. How could I look into data and enable the condition statements.

Thanks,  
Yash

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [May 26, 2017, 11:51am UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249/2 "2017-05-26T11:51:29Z")

</div>

Hey,

Your syntax is actually malformed. Does logstash start with it?  
It should be

```auto
output {
    if [Log_Type] == "apache_Logs" {
        elasticsearch {
            hosts => ["localhost:9200"]
            action => 'index'
            index => 'apache-%{+YYYY.MM.dd}'
    }
    if [Log_Type] == "tomcat_Logs" {
        elasticsearch {
            hosts => ["tomcat:9200"]
            action => 'index'
            index => 'tomcat-%{+YYYY.MM.dd}'
    }
}
```

---

<div class="post-metadata">

**Author:** ![yasvanth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yasvanth/32/45818_2.png) [@yasvanth](https://discuss.elastic.co/u/yasvanth)\
**Post date:** [May 26, 2017, 12:48pm UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249/3 "2017-05-26T12:48:07Z")

</div>

Thanks for your quick reply. I tried this but no success But I will give a try again. Should I need to inspect the doc using filter section or just in output section?

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [May 26, 2017, 12:57pm UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249/4 "2017-05-26T12:57:15Z")

</div>

If the event is already parsed and structured, there is no need for a filter section.  
Based what you said above,

> [@yasvanth](#):
>
> ...I have field named as Log\_type to apache or tomcat.

There should be fields inside the event JSON document like so:

```auto
{
    #other event fields
    "Log_type": "apache_Logs"
}
```

Is that the case? If so, it should work as-is.

---

<div class="post-metadata">

**Author:** ![yasvanth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yasvanth/32/45818_2.png) [@yasvanth](https://discuss.elastic.co/u/yasvanth)\
**Post date:** [May 26, 2017, 1:19pm UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249/5 "2017-05-26T13:19:20Z")

</div>

@paz thanks a million. It is small typo in the field in nxlog, fixed and now working fine. Thanks for your help.

---

<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:** [June 23, 2017, 1:20pm UTC](https://discuss.elastic.co/t/how-to-seperate-docs-in-logstash-to-different-es-index/87249/6 "2017-06-23T13:20:01Z")

</div>

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