Splunk Dev

Why does the query using an absolute value return better results than the query using a subsearch?

davidse
New Member

A query that uses the returned (single) value of a subquery is returning different results than if I simply type in the value as a hard coded string.

Query 1:
index=cfs_* "aeb78KaLh7VIphSVg9FSIxl46y4="

Returns:
- events = 1535
- hosts = 5
- source = 19
- sourcetype = 14

Query 2:
index=cfs_* [search index=cfs_* "662704824FF6C21E" | top limit=1 sessionId | fields + sessionId]

Returns:
- events = 1331
- hosts = 2
- source = 10
- sourcetypes = 6

with "[search index=cfs_* "662704824FF6C21E" | top limit=1 sessionId | fields + sessionId]" returning: aeb78KaLh7VIphSVg9FSIxl46y4= when run by itself.

Why these two different result sets simply because the value returned in Option 2 is from a query vs. a hard coded value?

Tags (1)
0 Karma

somesoni2
Revered Legend

So your query 1 is this

index=cfs_* "aeb78KaLh7VIphSVg9FSIxl46y4="

The subsearch, when normalized, will be translated as (assuming the value returned is same)

index=cfs_* (sessionId="aeb78KaLh7VIphSVg9FSIxl46y4=")

So, the subsearch version expects that your data in index=cfs_* has a field called sessionId with value "aeb78KaLh7VIphSVg9FSIxl46y4=", whereas the hard-coded value version just searches that the raw data of the events in index=cfs_* has word/string "aeb78KaLh7VIphSVg9FSIxl46y4=". There may be events where the string "aeb78KaLh7VIphSVg9FSIxl46y4=" is available but not extracted as field sessionId, and thus the difference. Just to confirm my theory, please run following, for the same time range, and see if it matches your first query's result.

index=cfs_* [search index=cfs_* "662704824FF6C21E" | top limit=1 sessionId | eval search=sessionId |table search]
0 Karma

davidse
New Member

Answered my own question. This is the difference between named fields and the value itself in unmapped / un-named / different fields. This query returns the same results.

index=cfs_* [search index=cfs_* "662704824FF6C21E" | top limit=1 sessionId | fields + sessionId | rename sessionId as query]

"query" is dropped by splunk as a keyword, resulting in just the value being used for the subsequent query. Apparently you can use the "return" macro as well, but I could not get this to work.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Please accept an answer.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...