# Kv filter plugin when there are spaces in key and value

**URL:** https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120
**Category:** Logstash
**Created:** [February 6, 2016, 1:33pm UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120 "2016-02-06T13:33:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![techrawther](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@techrawther](https://discuss.elastic.co/u/techrawther)
#### Post date: [February 6, 2016, 1:33pm UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120/1 "2016-02-06T13:33:15Z")

</div>

I am facing challenges in using kv filter plugin. I wanted to split data based on colon : . I have spaces in the key and also value. I wanted to have the data filtered with the key (entire key) with the spaces removed and not remove any space in the value(but can remove the spaces appearing in very first). How can I get that using kv

for eg: if i have data like and wanted to separarate key, value as mentioned below.

```
         Job id: this is the JOBID 
         key as "Jobid " 
         value as "this is the JOBID"

```

I have data like this

I tried following

1. Option 1

2. Option 2

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [February 6, 2016, 1:43pm UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120/2 "2016-02-06T13:43:04Z")

</div>

If you have spaces in your keys and values, I am assuming you are not using space to [split fields](https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html#plugins-filters-kv-field_split)?  
What does a full message look like? How is key-value pairs separated in the record?

---

<div class="post-metadata">

### Author: ![techrawther](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@techrawther](https://discuss.elastic.co/u/techrawther)
#### Post date: [February 6, 2016, 1:50pm UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120/3 "2016-02-06T13:50:38Z")

</div>

Thanks Christian for your response  
Following is a typical data I have. I am not using the "[split fields] ([https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html#plugins-filters-kv-field\_split](https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html#plugins-filters-kv-field_split))" and I am splitting the data using value\_split =\> ":"

```
    message " Job id: this is the JOBID : this will the submitted in windows"

```

I would like to have

```
     key as "Jobid" 
     value as "this is the JOBID : this will the submitted in windows"
```

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [February 6, 2016, 2:07pm UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120/4 "2016-02-06T14:07:30Z")

</div>

So you don't have multiple key-value pairs in the message, the message contains the default field separator and the value contains the character you use to separate key from value? Try setting the field separator to something that does not exist in the key or the value and see if that works. If this is not the case, I don't think this is what the kv filter was designed to parse, so I would look into using either the grok or ruby filters for this.

---

<div class="post-metadata">

### Author: ![techrawther](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@techrawther](https://discuss.elastic.co/u/techrawther)
#### Post date: [February 6, 2016, 4:23pm UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120/5 "2016-02-06T16:23:02Z")

</div>

Thanks Christian. That really helped.

I gave it as some thing like below and i did the magic

```
		kv {	trimkey => "\s"
			value_split => ":"
			field_split => "&?&"
		}
```

---

<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, 5:12am UTC](https://discuss.elastic.co/t/kv-filter-plugin-when-there-are-spaces-in-key-and-value/41120/6 "2017-07-06T05:12:50Z")

</div>


