# Using KV filter

**URL:** <https://discuss.elastic.co/t/using-kv-filter/56221>\
**Category:** Logstash\
**Created:** [July 24, 2016, 1:21am UTC](https://discuss.elastic.co/t/using-kv-filter/56221 "2016-07-24T01:21:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soodlikesjava](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@soodlikesjava](https://discuss.elastic.co/u/soodlikesjava)\
**Post date:** [July 24, 2016, 1:21am UTC](https://discuss.elastic.co/t/using-kv-filter/56221/1 "2016-07-24T01:21:47Z")

</div>

Hi team I have a requirement to create fields by matching key\>value in the event . but KV filter should consider only those KV filters which are enclosed under brackets like  
message : logging data (key1\>value1,key2\>value2) and rest key3\>value3

now if i use kv filter to create search fields key1 and key2 . Kv filter field\_split should consider only key1 and key2 and it should not consider key3 .

when i am using below config , it is considering key3 also :

kv {  
source =\> "logmessage"  
allow\_duplicate\_values =\> false  
field\_split =\> "(^\s,?\s$)"  
value\_split =\> "\>?"  
}

Actual output :  
key1 =\> value1  
key2 =\> value2  
key3 =\> value3

Expected output should be :

key1 =\> value1  
key2 =\> value2

Please suggest...

---

<div class="post-metadata">

**Author:** ![jpcarey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpcarey/32/46668_2.png) [@jpcarey](https://discuss.elastic.co/u/jpcarey)\
**Post date:** [July 24, 2016, 2:02am UTC](https://discuss.elastic.co/t/using-kv-filter/56221/2 "2016-07-24T02:02:23Z")

</div>

Use a grok to pull out the content between parenthesis / brackets. Then, you can run the kv filter directly on that new field (use @metdata or just drop the field on a successful kv execution.

---

<div class="post-metadata">

**Author:** ![soodlikesjava](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@soodlikesjava](https://discuss.elastic.co/u/soodlikesjava)\
**Post date:** [July 24, 2016, 2:04am UTC](https://discuss.elastic.co/t/using-kv-filter/56221/3 "2016-07-24T02:04:02Z")

</div>

> [@jpcarey](#):
>
> @metdata

Can you please explain what @metdata field does , if i dont use mutate to remove field

---

<div class="post-metadata">

**Author:** ![jpcarey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpcarey/32/46668_2.png) [@jpcarey](https://discuss.elastic.co/u/jpcarey)\
**Post date:** [July 24, 2016, 2:11am UTC](https://discuss.elastic.co/t/using-kv-filter/56221/4 "2016-07-24T02:11:49Z")

</div>

Check out [this blog](https://www.elastic.co/blog/logstash-metadata). @metdata is a special field/object that is normally not output. This allows for creating ephemeral fields that can be used for logic and routing. If you are printing to stdout, you need to enable @metadata output (the blog covers this).

---

<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:** [July 6, 2017, 4:46am UTC](https://discuss.elastic.co/t/using-kv-filter/56221/5 "2017-07-06T04:46:41Z")

</div>


