# Logstash : Grok : Out of sequence key:value filter

**URL:** <https://discuss.elastic.co/t/logstash-grok-out-of-sequence-key-value-filter/54269>\
**Category:** Logstash\
**Created:** [June 29, 2016, 11:20am UTC](https://discuss.elastic.co/t/logstash-grok-out-of-sequence-key-value-filter/54269 "2016-06-29T11:20:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hassanfarid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hassanfarid/32/10626_2.png) [@hassanfarid](https://discuss.elastic.co/u/hassanfarid)\
**Post date:** [June 29, 2016, 11:20am UTC](https://discuss.elastic.co/t/logstash-grok-out-of-sequence-key-value-filter/54269/1 "2016-06-29T11:20:27Z")

</div>

Hello, I have log lines that may report key:value pair out of order.

2016-06-01 08:52:52 [info]: key1:value1, key2:value2  
2016-06-01 08:52:52 [info]: key3:value3, key2:value2  
2016-06-01 08:52:52 [info]: key2:value2, key1:value1, key3:value3

I can find key:value pairs using below grok pattern a) if they appear in right order b)and they are for sure present  
%{TIMESTAMP\_ISO8601:timestamp} [%{WORD:logLEVEL}]: key1:%{WORD:value1}, key2:%{WORD:value2}

I want to be able to capture out of order and optionally skup some fields as well. As a result, I would like to create following object.

Line#1  
{  
"timeStamp": "2016-06-01 08:52:52",  
"logLEVEL":"info",

//all key value pairs mentioned  
"key1":"value1",  
"key2":"value2"  
}

Line#2  
{  
"timeStamp": "2016-06-01 08:52:52",  
"logLEVEL":"info",

//all key value pairs mentioned  
"key3":"value3",  
"key2":"value2"  
}

Line#3  
{  
"timeStamp": "2016-06-01 08:52:52",  
"logLEVEL":"info",

//all key value pairs mentioned  
"key1":"value1",  
"key2":"value2",  
"key3":"value3"  
}

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [June 29, 2016, 3:17pm UTC](https://discuss.elastic.co/t/logstash-grok-out-of-sequence-key-value-filter/54269/2 "2016-06-29T15:17:14Z")

</div>

Have you considered using the [kv](https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html) filter instead of direct grok? It should do what you're trying to do.

---

<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:50am UTC](https://discuss.elastic.co/t/logstash-grok-out-of-sequence-key-value-filter/54269/3 "2017-07-06T04:50:23Z")

</div>


