<?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: How to run a search and retrieve elements from a Splunk API in java in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73829#M18526</link>
    <description>&lt;P&gt;Can you tell me what value are you passing for searchQuery variable?&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2013 16:59:41 GMT</pubDate>
    <dc:creator>Neeraj_Luthra</dc:creator>
    <dc:date>2013-03-26T16:59:41Z</dc:date>
    <item>
      <title>How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73817#M18514</link>
      <description>&lt;P&gt;Hi.&lt;BR /&gt;
I am trying to run a search from a Splunk API in java, store the results with fields host, sourcetype, source in the JobResultsArgs and stored in an input stream. Now I want to run through each result and retrieve the host and source.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;public void search(String query,String startDate, String endDate){
        String url = System.getProperty("SPLUNK.HOST");
        int port = Integer.getInteger("SPLUNK.PORT");
        String username = System.getProperty("SPLUNK.USERNAME");
        String password = System.getProperty("SPLUNK.PASSWORD");
        String searchQuery_normal = "search * | head 100";



        Service client = new Service(url.trim(), port);
        client.login(username, password);
        JobArgs jobArgs = new  JobArgs(); 
        jobArgs.setEarliestTime(startDate);
        jobArgs.setLatestTime(endDate);
        Job job = client.getJobs().create(searchQuery_normal,jobArgs);  
        while (!job.isDone()) {
             try {
                 Thread.sleep(500);
             } catch (InterruptedException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
         }

         JobResultsArgs jobRes = new JobResultsArgs();
         String[] fields = {"_raw" , "host", "sourcetype", "source"};
         jobRes.setFieldList(fields);
         jobRes.setCount(2500);
         InputStream inpStream = job.getResults(jobRes);  
         System.out.println("result size: " + job.getResultCount());
         for (int i = 0; i &amp;lt; job.getResultCount(); i++){
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here I want to get the host and source. I am stuck here. &lt;BR /&gt;
Can you please help me, how I can proceed. I know I can use the RessultReadonJson but not sure how to retrieve those elements. &lt;BR /&gt;
Is there an example of this kind?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 17:14:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73817#M18514</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-25T17:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73818#M18515</link>
      <description>&lt;P&gt;Try this code:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;InputStream inpStream = job.getResults(jobRes);&lt;BR /&gt;
System.out.println("result size: " + job.getResultCount());&lt;BR /&gt;
ResultsReaderXml resultsReader = new ResultsReaderXml(inpStream);&lt;BR /&gt;
Event event = null;&lt;BR /&gt;
while ((event = resultsReader.getNextEvent()) != null) {&lt;BR /&gt;
    System.out.println("_raw:" + event.get("_raw"));&lt;BR /&gt;
    System.out.println("host:" + event.get("host"));&lt;BR /&gt;
    System.out.println("sourcetype:" + event.get("sourcetype"));&lt;BR /&gt;
    System.out.println("source:" + event.get("source"));&lt;BR /&gt;
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;Similarly you can use ResultsReaderJson as well.&lt;/P&gt;

&lt;P&gt;You can also refer to sample code in the &lt;A href="http://dev.splunk.com/view/SP-CAAAEHQ" target="_blank"&gt;How-To section of our Java SDK&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:36:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73818#M18515</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2020-09-28T13:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73819#M18516</link>
      <description>&lt;P&gt;Thank You for the quick response.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 18:20:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73819#M18516</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-25T18:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73820#M18517</link>
      <description>&lt;P&gt;System.out.println("result size: " + job.getResultCount()); &lt;/P&gt;

&lt;P&gt;Does this statement gives the number of times the search query was found or 100 as initializes in the searchQuery_normal becausde i am getting 100 everytime.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 20:07:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73820#M18517</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-25T20:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73821#M18518</link>
      <description>&lt;P&gt;getResultsCount is the total count of results returned by the job. Keep in mind that this is different from getEventCount. You can read more &lt;A href="http://dev.splunk.com/view/SP-CAAAEHQ"&gt;here&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Btw, I think the reason you are getting 100 is because of your you have " ... | head 100" in your search query.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2013 20:46:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73821#M18518</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-25T20:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73822#M18519</link>
      <description>&lt;P&gt;Can we give &lt;BR /&gt;
Job job = client.getJobs().create(searchQuery,jobArgs); &lt;BR /&gt;
without giving the "...|head 100". I was thrown an error when i tried to give just the search query,start time and end time arguments.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 14:15:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73822#M18519</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T14:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73823#M18520</link>
      <description>&lt;P&gt;You may be passing invalid arguments during creation. Keep in mind that the list of arguments are different for creation vs. getting results. Please review the documentation for &lt;A href="http://dev.splunk.com/view/SP-CAAAEHQ"&gt;How to run searches&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 14:59:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73823#M18520</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-26T14:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73824#M18521</link>
      <description>&lt;P&gt;I want to search for a query with in the starttime and endTime. So i am taking jobargs.setEarliestTime(startTime) and jobargs.setLatestTime(endTime) and sending these arguments alsong with creting a seatch job.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 15:09:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73824#M18521</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T15:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73825#M18522</link>
      <description>&lt;P&gt;You may not be passing the values in the right format. Here is a way to pass time strings and you can also pass in relative time like "-20m@m". Please go through the &lt;A href="http://dev.splunk.com/view/SP-CAAAEHQ"&gt;documentation&lt;/A&gt; to learn more about job arguments.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;JobArgs jobArgs = new JobArgs();&lt;BR /&gt;
jobArgs.setEarliestTime("2013-03-26T00:00:00.000-07:00");&lt;BR /&gt;
Job job = service.getJobs().create("search index=_internal", jobArgs);&lt;BR /&gt;
while (!job.isDone()) {&lt;BR /&gt;
    Thread.sleep(500);&lt;BR /&gt;
}&lt;BR /&gt;
System.out.println(job.getResultCount());&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 15:28:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73825#M18522</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-26T15:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73826#M18523</link>
      <description>&lt;P&gt;This is the way i am passing the time strings but i need to pass a query which is a string I stored in a variable. I want to pass that string. Instead of &lt;BR /&gt;
Job job = service.getJobs().create("search index=_internal", jobArgs); can i use &lt;BR /&gt;
Job job = service.getJobs().create(searchQuery, jobArgs);&lt;BR /&gt;
where searchQuery has the string i am search for.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 16:19:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73826#M18523</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T16:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73827#M18524</link>
      <description>&lt;P&gt;Yes, you can.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 16:41:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73827#M18524</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-26T16:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73828#M18525</link>
      <description>&lt;P&gt;When i tried like that it is showing an error : &lt;/P&gt;

&lt;P&gt;HTTP 400 -- Error in 'SearchParser': Missing a search command before '"'.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 16:48:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73828#M18525</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T16:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73829#M18526</link>
      <description>&lt;P&gt;Can you tell me what value are you passing for searchQuery variable?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 16:59:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73829#M18526</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-26T16:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73830#M18527</link>
      <description>&lt;P&gt;"" + \"java.sql.SQLException: Closed Connection\" &lt;/P&gt;

&lt;P&gt;This is the query i am passing with escape character for the quotes in the string&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 17:10:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73830#M18527</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T17:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73831#M18528</link>
      <description>&lt;P&gt;Try this - searchQuery = "search java.sql.SQLException: Closed Connection";&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 17:17:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73831#M18528</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-26T17:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73832#M18529</link>
      <description>&lt;P&gt;Thanks a lot. Its working&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 18:16:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73832#M18529</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T18:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73833#M18530</link>
      <description>&lt;P&gt;Instead of giving the search string directly as  "search java.sql.SQLException: Closed Connection" can we store that in a variable and use it as we are passing that string from another method.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 18:36:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73833#M18530</guid>
      <dc:creator>kalyani1184</dc:creator>
      <dc:date>2013-03-26T18:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73834#M18531</link>
      <description>&lt;P&gt;Yeah, absolutely. Just make sure to put the &lt;CODE&gt;search&lt;/CODE&gt; keyword before the search criteria. Good luck.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2013 18:48:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73834#M18531</guid>
      <dc:creator>Neeraj_Luthra</dc:creator>
      <dc:date>2013-03-26T18:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to run a search and retrieve elements from a Splunk API in java</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73835#M18532</link>
      <description>&lt;P&gt;@kalyani1184 -&amp;gt; could you please help me in export the search results in splunk java sdk.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 12:14:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-a-search-and-retrieve-elements-from-a-Splunk-API-in/m-p/73835#M18532</guid>
      <dc:creator>harikag</dc:creator>
      <dc:date>2019-07-29T12:14:30Z</dc:date>
    </item>
  </channel>
</rss>

