Splunk Search

the search results disappear / how to keep them longer (python SDK)

tomasv
Explorer

Hi all,

I'm writing a cron job (using the Python SDK) that does a search and exports the data to a CSV file (to analyze it in a different app). The result usually is a few hundreds thousands rows (~ a million or so), so I need to fetch it piecewise (by 50k). The problem is that sometimes the result suddenly disappears after fetching the first few segments.

How to get rid of that? Is there an option to mark a result as 'do not remove' or something like that?

ineeman
Splunk Employee
Splunk Employee

Great question tomasv! The real answer has to do with the TTL of the search job. The default value is 600, and it unfortunately does not get reset when you get results from the job. You have a few options:

  1. You can call my_job.touch() after every call to my_job.results(...) - that will reset the TTL.
  2. You can explicitly set a longer TTL with `my_job.set_ttl(6000)' (or some other number, of course).

The other thing to note is that if you truly have hundreds of thousands of rows you need to get out of a single search, you may be better suited with using the search/jobs/export endpoint. In the Python SDK, you can take a look at the export sample here, which shows you how to do it. The benefit of the export endpoint is that it will simply stream the results to you as they are ready, so you don't have to keep paginating. You might find that this is a faster mechanism.

Let me know if this makes sense, and if not, I can add some more details.

ineeman
Splunk Employee
Splunk Employee

thanks - let us know if you need anything else. Also, don't forget to select an answer.

0 Karma

tomasv
Explorer

Great answer ineeman! I haven't tried the export endpoint yet, but the touch() seems to be working just fine.

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

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...