Splunk Search

How to filter a list of timestamps less than _time

weidertc
Contributor

I need to filter a list of timestamps which are less than _time.

this works:

| makeresults count=1
| eval timestamps = mvappend("1570000000", "1570000020")
| eval older = mvfilter(timestamps < 1570000010)

 

but the compared value is whatever is in _time.  this does not work:

| makeresults count=1
| eval timestamps = mvappend("1570000000", "1570000020")
| eval _time = 1570000010
| eval older = mvfilter(timestamps < _time)

 

I know timestamps work, because this does work:

| makeresults count=1
| eval timestamps = mvappend("1570000000", "1570000020")
| eval older = mvfilter(timestamps < now())

 

Why does now() and static values work, but this does not:

| makeresults count=1
| eval timestamps = mvappend("1570000000", "1570000020")
| eval now_time = now()
| eval older = mvfilter(timestamps < now_time)

 

How can i get a variable in there to compare, since i need to compare the list to _time?

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

mvfilter can only reference one field at a time

Description

This function filters a multivalue field based on an arbitrary Boolean expression. The Boolean expression can reference ONLY ONE field at a time.

https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions#mvfilter...

Try like this:

| makeresults count=1
| eval timestamps = mvappend("1700000000", "1800000020")
| foreach mode=multivalue timestamps
    [| eval older=if(<<ITEM>> < _time, mvappend(older,<<ITEM>>),older)]

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

mvfilter can only reference one field at a time

Description

This function filters a multivalue field based on an arbitrary Boolean expression. The Boolean expression can reference ONLY ONE field at a time.

https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions#mvfilter...

Try like this:

| makeresults count=1
| eval timestamps = mvappend("1700000000", "1800000020")
| foreach mode=multivalue timestamps
    [| eval older=if(<<ITEM>> < _time, mvappend(older,<<ITEM>>),older)]

weidertc
Contributor

whoa! i didn't know about mode=multivalue.  thanks!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Have you tried using single quotes to tell eval you're referring to a field name?

| eval older = mvfilter(timestamps < '_time')

 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...