Knowledge Management

How to pass the values of an evaluated field into a summary index with collect?

rcorfield
Explorer

Hi

I am trying to adjust an existing process which collects results of a query into a summary index. What I'm trying to do is add a new evaluated field and pass it into the summary index. I've been looking at the 'marker' option to 'collect', but that passes a string directly rather than the value of the field. Is there any way to pass the value of the field?

This is roughly what I'm trying:

index=<index> <query>
   | eval score1 = if(<subquery1>, 1, 0)
   | eval score2 = if(<subquery2>, 1, 0)
   | eval score_total = score1 + score2
| collect index=<summary_index> marker="score_total=score_total"

I was naively hoping that the 'score_total' field in the summary index (which now exists) would hold the evaluated numeric value, but unfortunately (for me) it contains the string 'score_total'.

Is there any way to achieve what I'm trying to do here? Or some alternative?

Thanks in advance.

Richard

0 Karma
1 Solution

rcorfield
Explorer

In the end I was able to solve my problem with the help of a similar question that had been asked previously:
https://answers.splunk.com/answers/224003/why-am-i-not-able-to-get-any-dynamic-content-using.html

I added the content I needed to the _raw field and this was then available as a field in the summary index:

 index=<index> <query>
    | eval score1 = if(<subquery1>, 1, 0)
    | eval score2 = if(<subquery2>, 1, 0)
    | eval score_total = score1 + score2
    | eval _raw=_raw.", score_total=".score_total
 | collect index=<summary_index>

View solution in original post

0 Karma

rcorfield
Explorer

In the end I was able to solve my problem with the help of a similar question that had been asked previously:
https://answers.splunk.com/answers/224003/why-am-i-not-able-to-get-any-dynamic-content-using.html

I added the content I needed to the _raw field and this was then available as a field in the summary index:

 index=<index> <query>
    | eval score1 = if(<subquery1>, 1, 0)
    | eval score2 = if(<subquery2>, 1, 0)
    | eval score_total = score1 + score2
    | eval _raw=_raw.", score_total=".score_total
 | collect index=<summary_index>
0 Karma

richgalloway
SplunkTrust
SplunkTrust

@rcorfield If your problem is resolved, please accept an answer to help future readers.

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

woodcock
Esteemed Legend

Why not just this?

 index=<index> <query>
    | eval score1 = if(<subquery1>, 1, 0)
    | eval score2 = if(<subquery2>, 1, 0)
    | eval marker = "score_total=" . score1 + score2
 | collect index=<summary_index>
0 Karma

rcorfield
Explorer

Thanks, but unfortunately I still couldn't see score_total in the summary index using this suggestion.

0 Karma

DalJeanis
Legend

Try concatenating. See if one of these matches your needs:

 | collect index=<summary_index> marker=tostring("score_total=".score_total)

OR

 | eval score_total="score_total=".score_total)
 | collect index=<summary_index> marker=score_total
0 Karma

rcorfield
Explorer

Thanks for your suggestions, but unfortunately it still wouldn't populate it with the value of the field, so instead I ended up with things like

marker="score_total".score_total

I solved it by appending my field to the _raw field in the end.

0 Karma
Get Updates on the Splunk Community!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...