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.
- events = 1535
- hosts = 5
- source = 19
- sourcetype = 14
index=cfs* [search index=cfs* "662704824FF6C21E" | top limit=1 sessionId | fields + sessionId]
- 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?
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.
Please accept an answer.
So your query 1 is this
The subsearch, when normalized, will be translated as (assuming the value returned is same)
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]