Splunk Search

Unable to query on multiple extracted fields

sivathemass
Engager

I've  a log like below and I want to extract the fields "country", "currency"

"{"id":1, "message":"country=US&currency=USD"}.


I wrote SPL 
index="main"| rex max_match=0 field=message "(?<key>\w+)=(?<value>[^&]+)" | eval z=mvzip(key, value, "~") | mvexpand z | rex field=z "(?<key>[^~]+)~(?<value>.*)" | eval {key} = value

After extracting the fields, I can search based on only one field. 
This works .
index="main"| rex max_match=0 field=message "(?<key>\w+)=(?<value>[^&]+)" | eval z=mvzip(key, value, "~") | mvexpand z | rex field=z "(?<key>[^~]+)~(?<value>.*)" | eval {key} = value | search country=US 

This does not work
index="main"| rex max_match=0 field=message "(?<key>\w+)=(?<value>[^&]+)" | eval z=mvzip(key, value, "~") | mvexpand z | rex field=z "(?<key>[^~]+)~(?<value>.*)" | eval {key} = value | search country="US" AND currency="USD". 

It yields 0 results
Any pointers please? 

 

Labels (1)
0 Karma
1 Solution

to4kawa
SplunkTrust
SplunkTrust
| makeresults 
| eval _raw="{\"id\":1, \"message\":\"country=US&currency=USD\"}"
| spath
| spath message output=message
| rename message as _raw
| extract

rename to _raw is trick.

View solution in original post

to4kawa
SplunkTrust
SplunkTrust
| makeresults 
| eval _raw="{\"id\":1, \"message\":\"country=US&currency=USD\"}"
| spath
| spath message output=message
| rename message as _raw
| extract

rename to _raw is trick.

View solution in original post

Register for .conf21 Now! Go Vegas or Go Virtual!

How will you .conf21? You decide! Go in-person in Las Vegas, 10/18-10/21, or go online with .conf21 Virtual, 10/19-10/20.