<?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 API search limits to 1000 results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142433#M39546</link>
    <description>&lt;P&gt;When I use the Splunk API (from node.js) to query a given sid, I only get back 1000 results, even when supplying the count=0 argument. This particular sid happens to return a great many records -- over 6 million. When trying with an sid that returns much fewer records, say 5,000, they all are returned.&lt;/P&gt;

&lt;P&gt;Here is my code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var Request = require('request');  // 2.34.x

var options = {
    url: 'htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=0',
    method: 'GET',
    auth: {
        user: 'hector',
        pass: 'wouldntyouliketoknow'
    },
    rejectUnauthorized: false,
    requestCert: true,
    agent: false
};

Request(options, function(err, response, body) {
    err &amp;amp;&amp;amp; console.log('Error calling Splunk: ' + err);
    body = JSON.parse(body);
    body &amp;amp;&amp;amp; body.results &amp;amp;&amp;amp; console.log('query result count: ' + body.results.length);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;query result count: 1000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried using pagination like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var Request = require('request');

var internals = {};

var options = {
    url: 'htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset={offset}',
    method: 'GET',
    auth: {
        user: 'hector',
        pass: 'wouldntyouliketoknow'
    },
    rejectUnauthorized: false,
    requestCert: true,
    agent: false
};

internals.querySplunk = function (options, offset, callback) {

    options.originalUrl = options.url;
    options.url = options.url.replace('{offset}', offset);
    console.log(options.url);

    Request(options, function(err, response, body) {

        err &amp;amp;&amp;amp; console.log('Error calling Splunk: ' + err);

        body = JSON.parse(body);
        var resultCount = body.results.length;
        console.log('query result count: ' + resultCount);

        if (resultCount === 0) {
            console.log('Done getting results.');
            return callback();
        }

        offset += 300;
        options.url = options.originalUrl;
        internals.querySplunk(options, offset, callback);
    });
};

internals.querySplunk(options, 0, function () {
    console.log('Exiting.');
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=0&lt;BR /&gt;
    query result count: 300&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=300&lt;BR /&gt;
    query result count: 300&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=600&lt;BR /&gt;
    query result count: 300&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=900&lt;BR /&gt;
    query result count: 100&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=1200&lt;BR /&gt;
    query result count: 0&lt;BR /&gt;
    Done getting results.&lt;BR /&gt;
    Exiting.&lt;/P&gt;

&lt;P&gt;As you can see, it still only pages to 1,000 results. What gives?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 16:28:02 GMT</pubDate>
    <dc:creator>j6white</dc:creator>
    <dc:date>2020-09-28T16:28:02Z</dc:date>
    <item>
      <title>API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142433#M39546</link>
      <description>&lt;P&gt;When I use the Splunk API (from node.js) to query a given sid, I only get back 1000 results, even when supplying the count=0 argument. This particular sid happens to return a great many records -- over 6 million. When trying with an sid that returns much fewer records, say 5,000, they all are returned.&lt;/P&gt;

&lt;P&gt;Here is my code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var Request = require('request');  // 2.34.x

var options = {
    url: 'htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=0',
    method: 'GET',
    auth: {
        user: 'hector',
        pass: 'wouldntyouliketoknow'
    },
    rejectUnauthorized: false,
    requestCert: true,
    agent: false
};

Request(options, function(err, response, body) {
    err &amp;amp;&amp;amp; console.log('Error calling Splunk: ' + err);
    body = JSON.parse(body);
    body &amp;amp;&amp;amp; body.results &amp;amp;&amp;amp; console.log('query result count: ' + body.results.length);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;query result count: 1000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried using pagination like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var Request = require('request');

var internals = {};

var options = {
    url: 'htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset={offset}',
    method: 'GET',
    auth: {
        user: 'hector',
        pass: 'wouldntyouliketoknow'
    },
    rejectUnauthorized: false,
    requestCert: true,
    agent: false
};

internals.querySplunk = function (options, offset, callback) {

    options.originalUrl = options.url;
    options.url = options.url.replace('{offset}', offset);
    console.log(options.url);

    Request(options, function(err, response, body) {

        err &amp;amp;&amp;amp; console.log('Error calling Splunk: ' + err);

        body = JSON.parse(body);
        var resultCount = body.results.length;
        console.log('query result count: ' + resultCount);

        if (resultCount === 0) {
            console.log('Done getting results.');
            return callback();
        }

        offset += 300;
        options.url = options.originalUrl;
        internals.querySplunk(options, offset, callback);
    });
};

internals.querySplunk(options, 0, function () {
    console.log('Exiting.');
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=0&lt;BR /&gt;
    query result count: 300&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=300&lt;BR /&gt;
    query result count: 300&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=600&lt;BR /&gt;
    query result count: 300&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=900&lt;BR /&gt;
    query result count: 100&lt;BR /&gt;
    htttps://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=300&amp;amp;offset=1200&lt;BR /&gt;
    query result count: 0&lt;BR /&gt;
    Done getting results.&lt;BR /&gt;
    Exiting.&lt;/P&gt;

&lt;P&gt;As you can see, it still only pages to 1,000 results. What gives?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:28:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142433#M39546</guid>
      <dc:creator>j6white</dc:creator>
      <dc:date>2020-09-28T16:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142434#M39547</link>
      <description>&lt;P&gt;What search are you running? How are you running it? If it is from the REST API, what parameters are you sending to the REST API?&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2014 18:51:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142434#M39547</guid>
      <dc:creator>ineeman</dc:creator>
      <dc:date>2014-05-07T18:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142435#M39548</link>
      <description>&lt;P&gt;I am running a search in the Splunk client and then referencing its sid via the REST API query parameters.&lt;/P&gt;

&lt;P&gt;As you can see from the code above, the API query (with parameters) is:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://splunksvr:8089/servicesNS/hector/search/search/jobs/%5Bsid%5D/results?output_mode=json&amp;amp;count=0"&gt;https://splunksvr:8089/servicesNS/hector/search/search/jobs/[sid]/results?output_mode=json&amp;amp;count=0&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 19:58:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142435#M39548</guid>
      <dc:creator>j6white</dc:creator>
      <dc:date>2014-05-09T19:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142436#M39549</link>
      <description>&lt;P&gt;I explained my question poorly - I apologize. &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;What search are you running (i.e. what is the search string)? &lt;/LI&gt;
&lt;LI&gt;How are you executing it (are you running it through the UI and getting the &lt;SID&gt;, or running it through the API)?&lt;/SID&gt;&lt;/LI&gt;
&lt;LI&gt;If it is from the API, what code is running it? &lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The details you gave above only talk about how you are requesting results from a specific search, not about how that search was created, which is what we need to know.&lt;/P&gt;</description>
      <pubDate>Mon, 12 May 2014 15:10:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142436#M39549</guid>
      <dc:creator>ineeman</dc:creator>
      <dc:date>2014-05-12T15:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142437#M39550</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Why, specifically, is the search string relevant? I'm not sure it's necessary that I post it to the public internet.&lt;/LI&gt;
&lt;LI&gt;I executed the query using the Splunk web browser client. Sorry, I thought "running a search in the Splunk client" was clear. My mistake.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 12 May 2014 20:30:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142437#M39550</guid>
      <dc:creator>j6white</dc:creator>
      <dc:date>2014-05-12T20:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142438#M39551</link>
      <description>&lt;P&gt;If you search is &lt;STRONG&gt;non-transforming&lt;/STRONG&gt; (i.e: it returns &lt;EM&gt;events&lt;/EM&gt; but not &lt;EM&gt;results&lt;/EM&gt;, as it doesn't use commands like stats or timechart to perform aggregation), you don't want to hit the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1/RESTAPI/RESTsearch#search.2Fjobs.2F.7Bsearch_id.7D.2Fresults"&gt;/services/search/jobs/{SID}/results&lt;/A&gt; endpoint:&lt;/P&gt;

&lt;PRE&gt;
Returns the results of the search specified by {search_id}. This is the table that exists after all processing from the search pipeline has completed.

This is the primary method for a client to fetch a set of TRANSFORMED events. If the dispatched search does not include a transforming command, the effect is the same as get_events, however with fewer options.
&lt;/PRE&gt;

&lt;P&gt;...but rather the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1/RESTAPI/RESTsearch#search.2Fjobs.2F.7Bsearch_id.7D.2Fevents"&gt;&lt;STRONG&gt;/services/search/jobs/{SID}/events&lt;/STRONG&gt;&lt;/A&gt; endpoint:&lt;/P&gt;

&lt;PRE&gt;
Returns the events of the search specified by {search_id}. These events are the data from the search pipeline before the first "transforming" search command. This is the primary method for a client to fetch a set of UNTRANSFORMED events for the search job.

This endpoint is only valid if the status_buckets &amp;gt; 0 or the search has no transforming commands.
&lt;/PRE&gt;

&lt;P&gt;Also, if your goal is to perform massive event export, the best method to leverage is &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1/RESTAPI/RESTsearch#GET_search.2Fjobs.2Fexport"&gt;&lt;STRONG&gt;/services/search/export&lt;/STRONG&gt;&lt;/A&gt; endpoint.&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2014 00:11:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142438#M39551</guid>
      <dc:creator>hexx</dc:creator>
      <dc:date>2014-05-20T00:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: API search limits to 1000 results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142439#M39552</link>
      <description>&lt;P&gt;hexx: Thanks for your very succinct and insightful answer. It looks like the export endpoint is best for my needs.&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2014 15:12:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/API-search-limits-to-1000-results/m-p/142439#M39552</guid>
      <dc:creator>j6white</dc:creator>
      <dc:date>2014-05-20T15:12:05Z</dc:date>
    </item>
  </channel>
</rss>

