Getting Data In

Is event sampling possible using the REST API?

buntinas
Engager

The documentation describes how to set the sampling ratio in the Search app and dashboards, but not when using the REST API.

Is sampling possible using the REST API?

1 Solution

jkat54
SplunkTrust
SplunkTrust

&dispatch.sample_ratio=10 appears in the URL when I select 1:10.

So i will assume something like that is what you want to add to your request.

I did some testing, and I get multiple lists of results back.

The first list of results is the sample.

View solution in original post

jrizzo_splunk
Splunk Employee
Splunk Employee

The following worked for me.

$ splunk search 'index=_internal | stats count' -index_earliest 1493132552 -index_latest 1493404081 -sample_ratio 1000
INFO: Sampling disables usage of report acceleration summaries.
INFO: This search is sampling approximately 1 out of every 1000 events (seed=1317954456)
count
-----
   58





$ curl -sku user:pass https://localhost:8089/services/search/jobs/export --data-urlencode search='search index=_internal | stats count' -d output_mode=csv -d earliest_time='1493132552' -d latest_time='1493404081' -d sample_ratio='1000'
count
46

jkat54
SplunkTrust
SplunkTrust

Also, this will work:

 ... | eval a=random()%10 | where a=7

Thanks @micah in irc

0 Karma

jkat54
SplunkTrust
SplunkTrust

&dispatch.sample_ratio=10 appears in the URL when I select 1:10.

So i will assume something like that is what you want to add to your request.

I did some testing, and I get multiple lists of results back.

The first list of results is the sample.

jkat54
SplunkTrust
SplunkTrust

You might prefer to just use the | head command instead...

... | head 10

0 Karma

jkat54
SplunkTrust
SplunkTrust

I dont like how the results still had all 15 billion results even though the sample ratio was set. So I used a similar technique to achieve similar results. First I created a command called randomint, then i used it in my search like this:

 ...| randomint 1 100| where randomint=2

or

 ...| randomint 1 100| where randomint=34

This will give a ratio of 1:100 of random events when executed by the API. I put the randomint command in my toolkit app: https://splunkbase.splunk.com/app/3265/

Basically you're attaching a field called randomint to all the events in the search pipeline, and then you're using a where clause to narrow down to just events that match 1 number between 1 and 100. If you wanted a different ration, you'd just do something like ...| randomint 1:50 | where randomint=17

eyalsharon
New Member

Hi , I am also trying to understand if possible
Any update ?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...