# Parsing message using kv filter

**URL:** https://discuss.elastic.co/t/parsing-message-using-kv-filter/219267
**Category:** Logstash
**Created:** [February 13, 2020, 5:43pm UTC](https://discuss.elastic.co/t/parsing-message-using-kv-filter/219267 "2020-02-13T17:43:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![toms130](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toms130/32/58507_2.png) [@toms130](https://discuss.elastic.co/u/toms130)
#### Post date: [February 13, 2020, 5:43pm UTC](https://discuss.elastic.co/t/parsing-message-using-kv-filter/219267/1 "2020-02-13T17:43:15Z")

</div>

Hi all,

I'd like to parse some part of a message with VKv filter, and keep end of the message into another field.

Message is :  
`[MarketplaceGroup=data][MarketplaceId=10][AccountId=1234] updating 926 items`

My filter is :  
filter {  
kv {  
source =\> "message"  
field\_split\_pattern =\> "\]\["  
trim\_key =\> "\[\]"  
trim\_value =\> "\[\]"  
}  
}

Result I have is :  
{  
"MarketplaceGroup" =\> "data",  
"@timestamp" =\> 2020-02-13T17:15:30.615Z,  
"MarketplaceId" =\> "10",  
"AccountId" =\> "1234] updating 926 items",  
"message" =\> "[MarketplaceGroup=data] [MarketplaceId=10] [AccountId=1324] updating 926 items"  
}

result I'd like to have is :

{  
"MarketplaceGroup" =\> "data",  
"@timestamp" =\> 2020-02-13T17:15:30.615Z,  
"MarketplaceId" =\> "10",  
"AccountId" =\> "1234",  
"message" =\> "updating 926 items"  
}

I can't find how to define all my key/values are inside braces, and rest of field is what I want to keep in message field (or store in another field, whatever)

thanks  
thomas

---

<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: [February 13, 2020, 11:29pm UTC](https://discuss.elastic.co/t/parsing-message-using-kv-filter/219267/2 "2020-02-13T23:29:23Z")

</div>

I would

```
mutate { copy => { "message" => "otherMessage" } }
mutate { gsub => ["message", "[^\]]*$", "", "otherMessage", ".*\]([^\]]*)$", "\1" ] }

```

then kv the [message] field.

---

<div class="post-metadata">

### Author: ![toms130](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toms130/32/58507_2.png) [@toms130](https://discuss.elastic.co/u/toms130)
#### Post date: [February 14, 2020, 8:04am UTC](https://discuss.elastic.co/t/parsing-message-using-kv-filter/219267/3 "2020-02-14T08:04:12Z")

</div>

> [@Badger](#):
>
> I would
> 
> ```auto
> mutate { copy => { "message" => "otherMessage" } }
> mutate { gsub => ["message", "[^\]]*$", "", "otherMessage", ".*\]([^\]]*)$", "\1" ] }
> 
> ```
> 
> then kv the [message] field.

Ah, regex magic, it works like a charm!  
thanks badger

---

<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: [March 13, 2020, 8:04am UTC](https://discuss.elastic.co/t/parsing-message-using-kv-filter/219267/4 "2020-03-13T08:04:19Z")

</div>

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