Splunk Search

Why does limit=x on chart command doesn't work?

morethanyell
Builder

this search string

    sourcetype=something
    | chart sum(views) as Views over Uploader limit=5
    | sort - Views

easily gives you the idea that what you're asking is "give me the top 5 most viewed video of the uploaders". But it doens't work. I fully understand now that you head to use the head command to trim the result to the top 5. But why? Working search string:

    sourcetype=something
    | chart sum(views) as Views over Uploader
    | sort - Views
    | head 5
1 Solution

Ayn
Legend

limit is used for limiting how many columns the chart command should output when splitting by multiple fields, so if you do chart count by field1,field2 limit=5, that means Splunk will limit the field2 columns to 5. It doesn't take effect when splitting by only one field.

Also even if the limit argument would work like you had expected you would end up with undesired results in your first search. If you grab the first 5 results and THEN sort by Views, you'll likely not end up with the top 5 values as you didn't do the sorting until after you've limited the results.

View solution in original post

surenderjat
New Member

Ayn answered the reason why limit doesn't work on chart.
For you to get the desired result you can do the following after your chart command line.
| sort 5 views

0 Karma

Ayn
Legend

limit is used for limiting how many columns the chart command should output when splitting by multiple fields, so if you do chart count by field1,field2 limit=5, that means Splunk will limit the field2 columns to 5. It doesn't take effect when splitting by only one field.

Also even if the limit argument would work like you had expected you would end up with undesired results in your first search. If you grab the first 5 results and THEN sort by Views, you'll likely not end up with the top 5 values as you didn't do the sorting until after you've limited the results.

morethanyell
Builder

The training explained this but for some reason, I did not get it. It just clicked now. Thanks a lot, Ayn!

Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...