Splunk Search

How to query multiple conditions when the field name has a space

vjverma
Explorer

I need to run a query on the following lines:

index=i source=s earliest=-7W@W latest=@W | timechart span=1w count AS Overall count(eval(field1>0 )) AS F1Count count(eval("Field 2">0)) AS F2Count

The "Field 2" results in a syntax error saying "The eval expression for dynamic field '"Field 2">0' is invalid"

I can't rename the "Field 2". Is they any other way to query this data.

I could do
index=i source=s earliest=-7W@W latest=@W "Field 2">0| timechart span=1w count AS F2Count

but this requires me to run this query multiple times for each field.

Tags (3)
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Of course you can rename Field 2:

index=i source=s earliest=-7W@W latest=@W | rename "Field 2" as Field_2 | timechart span=1w count AS Overall count(eval(field1>0 )) AS F1Count count(eval(Field_2>0)) AS F2Count

Alternatively you can use single quotes in eval:

index=i source=s earliest=-7W@W latest=@W | timechart span=1w count AS Overall count(eval(field1>0 )) AS F1Count count(eval('Field 2'>0)) AS F2Count

Double quotes would make that a string that can't be compared with a number, causing that error.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Of course you can rename Field 2:

index=i source=s earliest=-7W@W latest=@W | rename "Field 2" as Field_2 | timechart span=1w count AS Overall count(eval(field1>0 )) AS F1Count count(eval(Field_2>0)) AS F2Count

Alternatively you can use single quotes in eval:

index=i source=s earliest=-7W@W latest=@W | timechart span=1w count AS Overall count(eval(field1>0 )) AS F1Count count(eval('Field 2'>0)) AS F2Count

Double quotes would make that a string that can't be compared with a number, causing that error.

vjverma
Explorer

Thank you. Worked like a charm.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...