<?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: REST API for pre-sorted data in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77849#M19688</link>
    <description>&lt;P&gt;Adding the sort command didn't get me what I'm looking for.  Neither for both synchronous and asynchronous searches.&lt;/P&gt;

&lt;P&gt;Let me describe more specifically what I'm looking for.  Below is the format of output I would like to get from the REST call.  &lt;/P&gt;

&lt;P&gt;userid  count&lt;BR /&gt;
340930  496&lt;BR /&gt;
129298  434&lt;BR /&gt;
34465   128&lt;BR /&gt;
100891  80&lt;/P&gt;

&lt;P&gt;This is possible by running the following search command directly on the server where the data exists.&lt;/P&gt;

&lt;P&gt;/opt/splunk/bin/splunk search "search event=spamreport | top limit=50 userid | table userid, count | sort - count" output=rawdata -auth $SPLUNKUSER:$SPLUNKPASS 2&amp;gt;/dev/null&lt;/P&gt;</description>
    <pubDate>Wed, 03 Oct 2012 14:45:28 GMT</pubDate>
    <dc:creator>abarkerSendGrid</dc:creator>
    <dc:date>2012-10-03T14:45:28Z</dc:date>
    <item>
      <title>REST API for pre-sorted data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77847#M19686</link>
      <description>&lt;P&gt;Hi Splunk Pro's,&lt;/P&gt;

&lt;P&gt;I'm looking for a way to grab processed, sorted data via a REST API call.  For instance when logged into the Splunk search dashboard, I can get a sorted list of data based on an event that I'm able to specify:&lt;/P&gt;

&lt;P&gt;"event=spamreport | top limit=50 userid | table userid, count"&lt;/P&gt;

&lt;P&gt;which processes the raw log data and returns an organized list of userid's sorted by their total spam report count.&lt;/P&gt;

&lt;P&gt;Is there a way to get this pre-processed, sorted data via a REST API call?  Using the same search string above, I've tried both synchronously returning results with /search/search/jobs/export as well as asynchronously returning results with /search/search/jobs to create a job and /search/search/jobs/JOBID/results to retrieve the data once the job is complete.  However, both approaches only give me the raw data, not the sorted list that I can see from the web search dashboard.  I've tried playing with the output_mode, but no option that I'm aware of produces the desired result.  &lt;/P&gt;

&lt;P&gt;Are there any options other than a REST API call?  I'm looking for something that is easily doable from the command line or a script and that doesn't require running the search from the same server that contains the log data.  &lt;/P&gt;

&lt;P&gt;Thanks very much!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2012 23:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77847#M19686</guid>
      <dc:creator>abarkerSendGrid</dc:creator>
      <dc:date>2012-10-02T23:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: REST API for pre-sorted data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77848#M19687</link>
      <description>&lt;P&gt;Have you tried adding the &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0/SearchReference/sort"&gt;sort command&lt;/A&gt; into the search pipeline you are using in the REST call&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search event=spamreport | top limit=50 userid | table userid, count | sort - count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2012 07:13:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77848#M19687</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2012-10-03T07:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: REST API for pre-sorted data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77849#M19688</link>
      <description>&lt;P&gt;Adding the sort command didn't get me what I'm looking for.  Neither for both synchronous and asynchronous searches.&lt;/P&gt;

&lt;P&gt;Let me describe more specifically what I'm looking for.  Below is the format of output I would like to get from the REST call.  &lt;/P&gt;

&lt;P&gt;userid  count&lt;BR /&gt;
340930  496&lt;BR /&gt;
129298  434&lt;BR /&gt;
34465   128&lt;BR /&gt;
100891  80&lt;/P&gt;

&lt;P&gt;This is possible by running the following search command directly on the server where the data exists.&lt;/P&gt;

&lt;P&gt;/opt/splunk/bin/splunk search "search event=spamreport | top limit=50 userid | table userid, count | sort - count" output=rawdata -auth $SPLUNKUSER:$SPLUNKPASS 2&amp;gt;/dev/null&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2012 14:45:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77849#M19688</guid>
      <dc:creator>abarkerSendGrid</dc:creator>
      <dc:date>2012-10-03T14:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: REST API for pre-sorted data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77850#M19689</link>
      <description>&lt;P&gt;Is this aggregated output format possible with a REST API call?  Is there another way to go about this?  The only requirement for me is that the API search doesn't require itself to be run on the same machine as the data.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2012 14:48:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77850#M19689</guid>
      <dc:creator>abarkerSendGrid</dc:creator>
      <dc:date>2012-10-03T14:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: REST API for pre-sorted data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77851#M19690</link>
      <description>&lt;P&gt;If you specify the "f" parameter in your request, you should be able to get your desired aggregated output. You can do this with both jobs/${search_id}/results as well as jobs/export. Below is a small code snippet for both of these calls.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
curl -k -u admin:changeme &lt;A href="https://localhost:8089/services/search/jobs/export" target="_blank"&gt;https://localhost:8089/services/search/jobs/export&lt;/A&gt; -d search="search index%3D_internal | top limit%3D10 sourcetype" -d output_mode=csv -d f=sourcetype -d f=count&lt;BR /&gt;
OR&lt;BR /&gt;
curl -k -u admin:changeme &lt;A href="https://localhost:8089/services/search/jobs/$%7Bsearch_id%5D/results" target="_blank"&gt;https://localhost:8089/services/search/jobs/${search_id]/results&lt;/A&gt; --get -d output_mode=csv -d f=sourcetype -d f=count&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Also, I am not sure if you are aware of the &lt;A href="http://dev.splunk.com/view/sdks/SP-CAAADP7" target="_blank"&gt;Splunk SDKs&lt;/A&gt; (Java, JavaScript, Python, PHP) but I would encourage accessing the REST APIs through them as they make it easier for you to manage and work with Splunk objects and you can stay in the comfort zone of your preferred language.&lt;/P&gt;

&lt;P&gt;If you need help or code sample to implement the commands above through any of the SDKs, feel free to contact &lt;A href="mailto:nluthra@splunk.com" target="_blank"&gt;me&lt;/A&gt;. &lt;/P&gt;

&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:33:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REST-API-for-pre-sorted-data/m-p/77851#M19690</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2020-09-28T12:33:58Z</dc:date>
    </item>
  </channel>
</rss>

