# Issue with custom parsing in grok filter

**URL:** https://discuss.elastic.co/t/issue-with-custom-parsing-in-grok-filter/172351
**Category:** Logstash
**Created:** [March 14, 2019, 2:22pm UTC](https://discuss.elastic.co/t/issue-with-custom-parsing-in-grok-filter/172351 "2019-03-14T14:22:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jprakash402](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jprakash402](https://discuss.elastic.co/u/jprakash402)
#### Post date: [March 14, 2019, 2:22pm UTC](https://discuss.elastic.co/t/issue-with-custom-parsing-in-grok-filter/172351/1 "2019-03-14T14:22:08Z")

</div>

Hi All,

We have a custom log file, which we need to parse to extract some required fields out of it. We have setup Logstash to parse the data and push it to Elasticsearch.

###### Sample log file.

```auto
{"level":"info","message":"API Request:stopInstance, user:user1@gmail.com, InstanceID:i-033daf56fhjb4102c, Message: User initiated EC2 STOP event","timestamp":"2019-03-13T15:54:09.313Z"}

```

We wanted to extract the fields as below.

```auto
level : info
EventName : stopInstance
UserID : user1@gmail.com
InstanceId : i-033daf56fhjb4102c

```

We tried to use custom regex patterns in grok filter but it didn't work out. We are getting grok parse error. Below is the test logstash config file.

```auto
input {
   stdin{}
}
filter {
    grok {
      match => ["message", '(?<EventName>(?<=API:).*?(?= ::))',"message", '(?<level>(?<=el\":\").*?(?=\",\")),"message", '(?<UserID>(?<=user:).*?(?=, Instance))',"message", '(?<InstanceID>(?<=eID).*?(?=, Message))'
        ]
    }
}
output {
   file {
      path => "./test"
   }
}

```

Could you guys help us here please?

---

<div class="post-metadata">

### Author: ![jprakash402](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jprakash402](https://discuss.elastic.co/u/jprakash402)
#### Post date: [April 10, 2019, 10:18am UTC](https://discuss.elastic.co/t/issue-with-custom-parsing-in-grok-filter/172351/2 "2019-04-10T10:18:32Z")

</div>

Can someone help us on this please

---

<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: [April 10, 2019, 11:08am UTC](https://discuss.elastic.co/t/issue-with-custom-parsing-in-grok-filter/172351/3 "2019-04-10T11:08:20Z")

</div>

I would suggest

```
    json { source => "message" }
    kv { field_split => ", " value_split => ":" }

```

you can then rename the field with a [mutate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) filter.

---

<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: [May 8, 2019, 11:08am UTC](https://discuss.elastic.co/t/issue-with-custom-parsing-in-grok-filter/172351/4 "2019-05-08T11:08:31Z")

</div>

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