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

.conf21 Now Fully Virtual!
Register for FREE Today!

We've made .conf21 totally virtual and totally FREE! Our completely online experience will run from 10/19 through 10/20 with some additional events, too!