<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python SDK Paginate Result Set in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168772#M2236</link>
    <description>&lt;P&gt;So I have a fairly simple python script i have been working on which gets the results from search and does some work on them. However i am having some trouble paginating through the results so i can pull in more than 50K results.&lt;/P&gt;

&lt;P&gt;Following the documentation works where it paginates the result set 10 at a time, but this takes a really long time, even just to iterate through 90K results.&lt;/P&gt;

&lt;P&gt;so even though my result count is about 90K the result reader is always giving me 0.&lt;/P&gt;

&lt;P&gt;For some reason no matter what i put for a value of the count other than 10 it breaks.&lt;/P&gt;

&lt;P&gt;Any thoughts would be great, thanks for your help.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchPayroll = """ &amp;lt;some search&amp;gt;"""
#returns a job from a service connection which performs the search
job = doSearch(searchPayroll)

 # Page through results by looping through sets of 10 at a time
resultCount = job["resultCount"]  # Number of results this job returned
offset = 0                     # Start at result 0
count = getMaxResults()                # 1 less that the max result count.
trackerpayroll=0                    #track result count
dictResultSetPayRoll = dict()


while (offset &amp;lt; int(resultCount)):
    kwargs_paginate = {"count": count,
                       "offset": offset}

    # Get the search results
    blocksearch_results = job.results(**kwargs_paginate)
    readerResults = results.ResultsReader(blocksearch_results)

    for result in readerResults:
       &amp;lt;do stuff here problem:
        result count (from job["resultCount"]) is 90K
        reader results = 0

    trackerpayroll += 1
    # Increase the offset to get the next set of results
    offset += count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Feb 2014 18:17:01 GMT</pubDate>
    <dc:creator>michaudel</dc:creator>
    <dc:date>2014-02-27T18:17:01Z</dc:date>
    <item>
      <title>Python SDK Paginate Result Set</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168772#M2236</link>
      <description>&lt;P&gt;So I have a fairly simple python script i have been working on which gets the results from search and does some work on them. However i am having some trouble paginating through the results so i can pull in more than 50K results.&lt;/P&gt;

&lt;P&gt;Following the documentation works where it paginates the result set 10 at a time, but this takes a really long time, even just to iterate through 90K results.&lt;/P&gt;

&lt;P&gt;so even though my result count is about 90K the result reader is always giving me 0.&lt;/P&gt;

&lt;P&gt;For some reason no matter what i put for a value of the count other than 10 it breaks.&lt;/P&gt;

&lt;P&gt;Any thoughts would be great, thanks for your help.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchPayroll = """ &amp;lt;some search&amp;gt;"""
#returns a job from a service connection which performs the search
job = doSearch(searchPayroll)

 # Page through results by looping through sets of 10 at a time
resultCount = job["resultCount"]  # Number of results this job returned
offset = 0                     # Start at result 0
count = getMaxResults()                # 1 less that the max result count.
trackerpayroll=0                    #track result count
dictResultSetPayRoll = dict()


while (offset &amp;lt; int(resultCount)):
    kwargs_paginate = {"count": count,
                       "offset": offset}

    # Get the search results
    blocksearch_results = job.results(**kwargs_paginate)
    readerResults = results.ResultsReader(blocksearch_results)

    for result in readerResults:
       &amp;lt;do stuff here problem:
        result count (from job["resultCount"]) is 90K
        reader results = 0

    trackerpayroll += 1
    # Increase the offset to get the next set of results
    offset += count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Feb 2014 18:17:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168772#M2236</guid>
      <dc:creator>michaudel</dc:creator>
      <dc:date>2014-02-27T18:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK Paginate Result Set</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168773#M2237</link>
      <description>&lt;P&gt;Please provide the code for your &lt;STRONG&gt;doSearch&lt;/STRONG&gt; method&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 13:25:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168773#M2237</guid>
      <dc:creator>paramagurukarth</dc:creator>
      <dc:date>2015-04-07T13:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK Paginate Result Set</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168774#M2238</link>
      <description>&lt;P&gt;In your implementation, if  &lt;STRONG&gt;dosearchjob&lt;/STRONG&gt; method internally uses &lt;STRONG&gt;splunk.search.dispatch&lt;/STRONG&gt;.. &lt;/P&gt;

&lt;P&gt;add maxEvents=30000000 to your **kwargs .. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;i.e, splunk.search.dispatch(searchquery,sessionKey=sessionkey,hostPath=baseurl,earliestTime=earliestTime,latestTime=latestTime,maxEvents=30000000)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and use the below implementation&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchjob = dosearchjob(quey)
    resultCount  = searchjob.resultCount
    offsetValue = 0
    searchresults = ""
    while offsetValue &amp;lt; resultCount:
        searchresults = searchresults +  str(searchjob.getFeed(mode='results', outputMode='csv',count=49999,offset=offsetValue))
        offsetValue = offsetValue + 49999
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use whatever &lt;STRONG&gt;outputMode&lt;/STRONG&gt;  you want &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2015 13:32:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-Paginate-Result-Set/m-p/168774#M2238</guid>
      <dc:creator>paramagurukarth</dc:creator>
      <dc:date>2015-04-07T13:32:05Z</dc:date>
    </item>
  </channel>
</rss>

