Splunk Search

Ruby sdk does not return all results from a saved search

bcordonnier
Engager

I am having a problem getting my saved_search to return all the results. I have the code snippet below:

saved_search = service.saved_searches["saved search name"]
job = saved_search.dispatch(:count=>0)
while !job.is_done?()
sleep(1)
end
stream = job.results(:count => 0)
results = Splunk::ResultsReader.new(stream)
count = 0
results.each do |result|
count += 1
end

This will end up having count = 100 which is not the right number. However, when I run THIS code:

stream = service.create_oneshot("full query written out", :count => 0)
results = Splunk::ResultsReader.new(stream)
count = 0
results.each do |result|
count += 1
end

I get a count = 538, which is the right answer. Clearly I am not telling the saved_search to give me back ALL the results, but I am not sure what I am doing wrong. I don't want to use the one_shot method because I would then have to keep the search query up to date in two separate places. I am new to ruby, so I could very well be making a dumb mistake somewhere.

0 Karma
1 Solution

fross_splunk
Splunk Employee
Splunk Employee

Congratulations, you've found a bug in the SDK! Your code is fine, though you only need the :count=>0 on the call to results, not to dispatch.

We'll get a bugfix release out, but for the moment you can install the SDK from the develop branch of the GitHub repository and your code should work.

View solution in original post

fross_splunk
Splunk Employee
Splunk Employee

Congratulations, you've found a bug in the SDK! Your code is fine, though you only need the :count=>0 on the call to results, not to dispatch.

We'll get a bugfix release out, but for the moment you can install the SDK from the develop branch of the GitHub repository and your code should work.

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!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...