Splunk Search

How can we fetch only 8 rows from a lookup?

ddrillic
Ultra Champion

Our top user ended up with the following query -

| inputlookup WHERE
[ | makeresults count=8 | streamstats count | eval WEEKSTART=relative_time($MYWEEKPICKER$,"-" + tostring(count - 1) + "w@w0")
| table WEEKSTART ]| rename WEEKSTART AS _time

The intention of makeresults count=8 is to create a dummy eight rows and by doing it, limit the results to only 8 rows starting with $MYWEEKPICKER$. Can we do it in any other way?

0 Karma

elliotproebstel
Champion

You are looking to retrieve only 8 rows from a lookup table, and those 8 rows each contain a timestamp? So something else is setting a value to the token $MYWEEKPICKER$, and you want to find 8 rows whose timestamp is the same as that value? Or more recent than that value?

0 Karma

ddrillic
Ultra Champion

-- and you want to find 8 rows whose timestamp is the same as that value

Of the data in the lookup file, we are trying to find out the eight previous dates available based the value from the drop-down.

0 Karma

elliotproebstel
Champion

Assuming your timestamps are in a field called timestamp_field, try this:
|inputlookup mylookup | sort - timestamp_field | where timestamp_field<=$MYWEEKPICKER$ | head 8 | fields timestamp_field

0 Karma

Kate_Lawrence-G
Contributor

You could always put a | head 8 command in the mix to restrict it to the first 8 results of the lookup file.

0 Karma

ddrillic
Ultra Champion

That's exactly the problem as we need to find the starting point and go back 8 rows.

0 Karma

Kate_Lawrence-G
Contributor

Perhaps you could you use a subsearch to find the data you are interested in | fields x and then pass those to the outer search?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...