# Is it possible to have different logstash parse patterns for diffrent logs files linked to the same index?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181>\
**Category:** Logstash\
**Created:** [September 5, 2019, 7:23am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181 "2019-09-05T07:23:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick78](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick78/32/53325_2.png) [@nick78](https://discuss.elastic.co/u/nick78)\
**Post date:** [September 5, 2019, 7:23am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181/1 "2019-09-05T07:23:05Z")

</div>

I would like to ask if it is possible to have different logstash parse patterns for different log files to the same index,? What i want to achieve is to have different parse patterns mapping to the same attributes and still put that data in the same index

---

<div class="post-metadata">

**Author:** ![tobydickinson](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@tobydickinson](https://discuss.elastic.co/u/tobydickinson)\
**Post date:** [September 5, 2019, 8:25am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181/2 "2019-09-05T08:25:16Z")

</div>

This is certanily possible. How are your inputs configured? The best way is to add a tag within the input plugin to flag it as a particular type of log. Then you can use an If statement within your filter plugin to handle events of different tags in different ways.

---

<div class="post-metadata">

**Author:** ![nick78](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick78/32/53325_2.png) [@nick78](https://discuss.elastic.co/u/nick78)\
**Post date:** [September 5, 2019, 10:49am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181/3 "2019-09-05T10:49:52Z")

</div>

Thank you for your feedback.  
My filebeat configuration is:

name: filebeat

filebeat.prospectors:

- type: log  
multiline.pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}|[a-zA-Z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}'  
multiline.negate: true  
multiline.match: after

- type: log  
multiline.pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}|[a-zA-Z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}'  
multiline.negate: true  
multiline.match: after

output:  
logstash:  
hosts: ["{{ logstash\_host }}:{{port}}"]

logging:  
level: debug

But i don't understand what i must do on the logstash configuration ?

---

<div class="post-metadata">

**Author:** ![tobydickinson](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@tobydickinson](https://discuss.elastic.co/u/tobydickinson)\
**Post date:** [September 5, 2019, 11:35am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181/5 "2019-09-05T11:35:46Z")

</div>

Okay you need to add the tags within Filebeat in this instance.

[https://www.elastic.co/guide/en/beats/filebeat/master/add-tags.html](https://www.elastic.co/guide/en/beats/filebeat/master/add-tags.html)

Try something like this:

```
type: log
multiline.pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}|[a-zA-Z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}'
multiline.negate: true
multiline.match: after

paths: /var/*.log

exclude_files: ['.yml']
document_type: application_log

fields_under_root: true
environment: {{ envi }}

processors:
 - add_tags:
    tags: [java-application-logs]

```

Perhaps remove the field data\_source name. Then you can use, within Logstash:

```
filter {
  if "java-application-logs" in [tags] {
    ... (processing java logs)
  }
  ....
}

```

Hope this helps.

---

<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 3, 2019, 11:35am UTC](https://discuss.elastic.co/t/is-it-possible-to-have-different-logstash-parse-patterns-for-diffrent-logs-files-linked-to-the-same-index/198181/6 "2019-10-03T11:35:47Z")

</div>

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