<?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 Re: search returns only 50000 events in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398170#M6825</link>
    <description>&lt;P&gt;Try below query (change query , time range , IP based on your requirement) and you need to download Splunk Python SDK to run this script &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import getpass
import json
sys.path.append('splunk-sdk-python-1.6.4')
import splunklib.client as client
import splunklib.results as results

splunkUser = raw_input("Enter Splunk Username: ")
splunkPassword = getpass.getpass("Enter Splunk Password: ")

splunkService = client.connect(host='&amp;lt;IP&amp;gt;', port=8089, username=splunkUser, password=splunkPassword, verify=0)
kwargs_export = {"earliest_time": "-15m", "latest_time": "now", "search_mode": "normal"}
job = splunkService.jobs.export("search index=_internal | stats count by host,sourcetype", **kwargs_export)

rr = results.ResultsReader(job)
f = open('results.txt', 'w')

for result in rr:
    if isinstance(result, dict):
        a = json.dumps(dict(result))
        f.write(a)
assert rr.is_preview == False
f.close()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jun 2019 09:13:24 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2019-06-06T09:13:24Z</dc:date>
    <item>
      <title>Search returns only 50000 events in Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398156#M6811</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;We are using the below python script to get the results from Splunk but the problem is that through UI we are getting more than 6lakh records. However, through API we are getting only 50000 records.&lt;/P&gt;
&lt;P&gt;Please help - what do I need to add in below script to get all the records?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;import urllib
import httplib2
import time
import re
from time import localtime,strftime
from xml.dom import minidom
import json
baseurl = 'https://localhost:8089'
username = ''
password = ''
myhttp = httplib2.Http()

#Step 1: Get a session key
servercontent = myhttp.request(baseurl + '/services/auth/login', 'POST',
                            headers={}, body=urllib.urlencode({'username':username, 'password':password}))[1]
sessionkey = minidom.parseString(servercontent).getElementsByTagName('sessionKey')[0].childNodes[0].nodeValue
print "====&amp;gt;sessionkey:  %s  &amp;lt;====" % sessionkey 

#Step 2: Create a search job    
searchquery = 'index="_internal" | head 10'
if not searchquery.startswith('search'):
searchquery = 'search ' + searchquery

searchjob = myhttp.request(baseurl + '/services/search/jobs','POST',
headers={'Authorization': 'Splunk %s' % sessionkey},body=urllib.urlencode({'search': searchquery}))[1]
sid = minidom.parseString(searchjob).getElementsByTagName('sid')[0].childNodes[0].nodeValue
print "====&amp;gt;sid:  %s  &amp;lt;====" % sid

#Step 3: Get the search status    
myhttp.add_credentials(username, password)
servicessearchstatusstr = '/services/search/jobs/%s/' % sid
isnotdone = True
while isnotdone:
    searchstatus = myhttp.request(baseurl + servicessearchstatusstr, 'GET')[1]
    isdonestatus = re.compile('isDone"&amp;gt;(0|1)')
    isdonestatus = isdonestatus.search(searchstatus).groups()[0]
    if (isdonestatus == '1'):
        isnotdone = False
print "====&amp;gt;search status:  %s  &amp;lt;====" % isdonestatus

#Step 4: Get the search results
services_search_results_str = '/services/search/jobs/%s/results?output_mode=json&amp;amp;count=0' % sid
searchresults = myhttp.request(baseurl + services_search_results_str, 'GET')[1]
print "====&amp;gt;search result:  [%s]  &amp;lt;====" % searchresults
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 23:09:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398156#M6811</guid>
      <dc:creator>bdhin</dc:creator>
      <dc:date>2020-06-17T23:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398157#M6812</link>
      <description>&lt;P&gt;Take a look at this answers post:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/242114/limited-results-when-running-searches-via-rest-api.html"&gt;https://answers.splunk.com/answers/242114/limited-results-when-running-searches-via-rest-api.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 20:48:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398157#M6812</guid>
      <dc:creator>kmorris_splunk</dc:creator>
      <dc:date>2019-06-03T20:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398158#M6813</link>
      <description>&lt;P&gt;@kmorris_splunk Yes,I tried but its not working&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 20:51:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398158#M6813</guid>
      <dc:creator>bdhin</dc:creator>
      <dc:date>2019-06-03T20:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398159#M6814</link>
      <description>&lt;P&gt;Since applying that change, have you restarted the Splunk instance?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 21:49:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398159#M6814</guid>
      <dc:creator>martynoconnor</dc:creator>
      <dc:date>2019-06-03T21:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398160#M6815</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;For large dataset export, please use &lt;CODE&gt;jobs/export&lt;/CODE&gt; endpoint &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/RESTREF/RESTsearch#search.2Fjobs.2Fexport"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.6/RESTREF/RESTsearch#search.2Fjobs.2Fexport&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 07:48:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398160#M6815</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-04T07:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398161#M6816</link>
      <description>&lt;P&gt;Hi @harsmarvania57 &lt;/P&gt;

&lt;P&gt;Can you please help me how to implement it in the above code?&lt;/P&gt;

&lt;P&gt;I am new to this one any help would be much appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 10:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398161#M6816</guid>
      <dc:creator>bdhin</dc:creator>
      <dc:date>2019-06-04T10:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398162#M6817</link>
      <description>&lt;P&gt;I'll prefer to do this using Splunk Python SDK, have a look at &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.6/Search/ExportdatausingSDKs#Use_Python_SDK_to_export_data"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.6/Search/ExportdatausingSDKs#Use_Python_SDK_to_export_data&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 11:33:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398162#M6817</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-04T11:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398163#M6818</link>
      <description>&lt;P&gt;You're hitting a default search limit. You can increase this value within limits.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[searchresults]
maxresultrows = 50000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And/or:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[restapi]
maxresultrows = 50000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You'll need to cycle Splunk after making the config change.&lt;/P&gt;

&lt;P&gt;Generally speaking, when you see nice round numbers like 50000, then you're encountering a limitation/parameter within limits.conf&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 16:00:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398163#M6818</guid>
      <dc:creator>codebuilder</dc:creator>
      <dc:date>2019-06-05T16:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398164#M6819</link>
      <description>&lt;P&gt;@harsmarvania57 Thanks for sharing the link.I was thinking to add the loop in my mentioned code to take count as 50000 and offset as 0 then count as 50000 and offset as 50000 and so on....I am not sure how to add this loop in my code.Can you please help me with that?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 23:58:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398164#M6819</guid>
      <dc:creator>bdhin</dc:creator>
      <dc:date>2019-06-05T23:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398165#M6820</link>
      <description>&lt;P&gt;Hi @codebuilder &lt;/P&gt;

&lt;P&gt;Thank you for sharing the answer,I was thinking to add the loop in my code to check the value for count and offset and based on that fetch the output.I am not sure how to implement that in my code.Can you please help me with that?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 00:00:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398165#M6820</guid>
      <dc:creator>bdhin</dc:creator>
      <dc:date>2019-06-06T00:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398166#M6821</link>
      <description>&lt;P&gt;I think it would be easier and more reliable if you instead narrow your search. Either by excluding data or narrowing the date range. It will perform much faster, so you can iterate through a call to that search in order to retrieve all the results you are seeking. It will be more simple to read and maintain, and will perform much better.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 01:52:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398166#M6821</guid>
      <dc:creator>codebuilder</dc:creator>
      <dc:date>2019-06-06T01:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398167#M6822</link>
      <description>&lt;P&gt;(forgot to mention)&lt;BR /&gt;
Also consider using a accelerated datamodel, your scenario sounds like a perfect candidate.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 01:53:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398167#M6822</guid>
      <dc:creator>codebuilder</dc:creator>
      <dc:date>2019-06-06T01:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398168#M6823</link>
      <description>&lt;P&gt;You'll not able to achieve this using loop because &lt;CODE&gt;results&lt;/CODE&gt; endpoint return only 50000 events. If you want to achieve this using &lt;CODE&gt;export&lt;/CODE&gt; endpoint with Splunk Python SDK then let me know and I'll provide script.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 08:14:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398168#M6823</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-06T08:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398169#M6824</link>
      <description>&lt;P&gt;Hi @harsmarvania57 sure please share the script that would be great&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 09:05:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398169#M6824</guid>
      <dc:creator>bdhin</dc:creator>
      <dc:date>2019-06-06T09:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: search returns only 50000 events</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398170#M6825</link>
      <description>&lt;P&gt;Try below query (change query , time range , IP based on your requirement) and you need to download Splunk Python SDK to run this script &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
import getpass
import json
sys.path.append('splunk-sdk-python-1.6.4')
import splunklib.client as client
import splunklib.results as results

splunkUser = raw_input("Enter Splunk Username: ")
splunkPassword = getpass.getpass("Enter Splunk Password: ")

splunkService = client.connect(host='&amp;lt;IP&amp;gt;', port=8089, username=splunkUser, password=splunkPassword, verify=0)
kwargs_export = {"earliest_time": "-15m", "latest_time": "now", "search_mode": "normal"}
job = splunkService.jobs.export("search index=_internal | stats count by host,sourcetype", **kwargs_export)

rr = results.ResultsReader(job)
f = open('results.txt', 'w')

for result in rr:
    if isinstance(result, dict):
        a = json.dumps(dict(result))
        f.write(a)
assert rr.is_preview == False
f.close()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2019 09:13:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Search-returns-only-50000-events-in-Python-script/m-p/398170#M6825</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-06-06T09:13:24Z</dc:date>
    </item>
  </channel>
</rss>

