Kv alphabetical sorting

Hi !

I just discovered that the kv filter plugin applies an alphabetical sorting on keys in output.

For example, i got a string like "a=1&c=2&b=3"

after the kv plugin i got this :
{
"a" : "1"
"b" : "3"
"c" : "2"
}

but i wanna keep the keys order like :

{
"a" : "1"
"c" : "3"
"b" : "2"
}

There is a solution to that except create my own filter ?

The fields are stored in a Ruby hash or a Java map (I think; I'd expect it to depend on the Logstash implementation). The order of the keys in such data structures is typically undefined so even if it looks like they're alphabetical now you shouldn't rely on it. It could also be the case that it's the JSON serializer that's sorting the keys, but since it obtains the keys from the internal hash/map it's not possible to maintain the original order.

Why does this matter?

thanks for this explanation :slight_smile:

it's important because i need to exclude some specifics params from the string, so i delete some keys in the array before implode on '&' to rebuild a "similar" string

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