Splunk Search

How to use tstats where with structured data source?

yuanliu
SplunkTrust
SplunkTrust

tstats shows an error if I include a JSON field in "where" clause.  Same happens to CSV fields.  For example, if my source is like

{"host": "<hostname>", "IP": "<IP address>"}

and I do a search

 

| tstats count where IP = 10.0.0.1

 

Splunk displays "When used for 'tstats' searches, the 'WHERE' clause can contain only indexed fields. Ensure all fields in the 'WHERE' clause are indexed. Properly indexed fields should appear in fields.conf."

The problem with fields.conf is that it doesn't deal with original data structure.  With JSON, there is always a chance that regex will not properly capture a field.  With CSV, failure rate is even higher.

Is there some way to do tstats with structured sources? (I notice that despite the warning, tstats still performs OK.  But I'd rather users don't see such error message.)

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

This sounds like a good use case for datamodels.

View solution in original post

johnhuang
Motivator

This sounds like a good use case for datamodels.

richgalloway
SplunkTrust
SplunkTrust

I think that message appears because of the minor breakers in the IP address.  Try overriding that with the TERM operator.

| tstats count where TERM(IP=10.0.0.1)

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

yuanliu
SplunkTrust
SplunkTrust

TERM will not be usable if multiple JSON paths have a node named IP.  With CSV, it's even harder, if at all possible, to define a TERM.  I will explore datamodel as @johnhuang suggested.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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 ...