# Add field dynamically based on different match

**URL:** <https://discuss.elastic.co/t/add-field-dynamically-based-on-different-match/171286>\
**Category:** Logstash\
**Created:** [March 7, 2019, 11:19am UTC](https://discuss.elastic.co/t/add-field-dynamically-based-on-different-match/171286 "2019-03-07T11:19:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsuijie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsuijie/32/41671_2.png) [@tsuijie](https://discuss.elastic.co/u/tsuijie)\
**Post date:** [March 7, 2019, 11:19am UTC](https://discuss.elastic.co/t/add-field-dynamically-based-on-different-match/171286/1 "2019-03-07T11:19:51Z")

</div>

We'd like to add an index based on which pattern was actually hit, which looks like this, but it won't work:

```auto
filter {
  grok {
    patterns_dir => "./patterns"
    match => {
      "message" => "%{A}"
    }
    add_field => { 'type' => 'A' }
  }
  grok {
    patterns_dir => "./patterns"
    match => {
      "message" => "%{B}"
    }
    add_field => { 'type' => 'B' }
  }
}

```

---

<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:** [April 4, 2019, 11:19am UTC](https://discuss.elastic.co/t/add-field-dynamically-based-on-different-match/171286/2 "2019-04-04T11:19:59Z")

</div>

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