Splunk Search

stats count returns different results for indexed field

bschaap
Path Finder

I'm having difficulty understanding why Query 2 is returning a different count than the other two queries. The cluster_name field is an indexed field. Does anyone know why this is occurring and have any suggestions to resolve or troubleshoot this issue?

Query 1
index=infra_k8s* sourcetype="kube:objects:pods" | stats count by cluster_name
cluster_name count
...
clusterxyz 436
...

Query 2
index=infra_k8s* sourcetype="kube:objects:pods" cluster_name=clusterxyz | stats count by cluster_name
cluster_name count
clusterxyz 68

Query 3
index=infra_k8s* sourcetype="kube:objects:pods" | eval cluster=cluster_name | search cluster="clusterxyz" | stats count by cluster
cluster count
clusterxyz 436

0 Karma

DalJeanis
Legend

Okay, so there are two different relevant possibilities.

Run your other queries and something like this across the same time frame.

| tstats count where index=infra_k8s* sourcetype="kube:objects:pods" by cluster_name

That will give you the counts by solely the cluster_name fields that were established at index time. That should match your 68.

Any more than those, are from fields that are being extracted at search time.

(I'm assuming that devonprem in query3 is your actual clustername, or that every event in cluster devonprem is coincidentally having clusterxyz extracted also.)

0 Karma

bschaap
Path Finder

I was trying to make my queries generic but must have skipped over that one. I fixed the 3rd query of my original post.

I just tried tstats and it returned a count of 436 rather than 68.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...