Splunk Search

How to use "collect" and keep the timestamp and field extractions of the event?

jameshgibson
Path Finder

So I have used collect to save some events into a summary index. The problem is all of the timestamp information is lost which makes the info next to useless. It desides to default all the events to the search time.

It also drops all the field extractions that I set up which is a pain but can be worked around at a push.

pseudo search:

sourcetype=x my_field=name | rex=something "do_some_extractions" | collect index=summary
1 Solution

jameshgibson
Path Finder

The problem was that the _raw field came from a database and were not prefixed by a timestamp. So what I did in the end was add the following to prepend it:

my search | eval _raw=_time + ": " + _raw | collect index=summary

I don't have any way of adding the field extractions though that can be done at search time manually.

View solution in original post

jameshgibson
Path Finder

The problem was that the _raw field came from a database and were not prefixed by a timestamp. So what I did in the end was add the following to prepend it:

my search | eval _raw=_time + ": " + _raw | collect index=summary

I don't have any way of adding the field extractions though that can be done at search time manually.

LeeSart
Explorer

You sir are a genius!
I know this is an old post, but this is the only solution I've come across that fully solves the issue.
Pretty much every other post has some variation of | eval EventTime = _time, which is a decent workaround but doesn't preserve the _time field.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...