<?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: Java SDK: Why am I only getting one field with stats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249863#M74570</link>
    <description>&lt;P&gt;To me, this sounds like you are not running the search within the same application context.&lt;/P&gt;

&lt;P&gt;Either set the permissions for the "response_time" field extraction to global or make sure to set the search context to the correct application for both searches (web UI and Java SDK).&lt;/P&gt;

&lt;P&gt;That should solve your problem.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2016 20:46:55 GMT</pubDate>
    <dc:creator>rfujara_splunk</dc:creator>
    <dc:date>2016-02-01T20:46:55Z</dc:date>
    <item>
      <title>Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249857#M74564</link>
      <description>&lt;P&gt;I'm attempting to run the following search using the Splunk Java SDK:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="[my_index]" sourcetype="[my_index]" | stats avg(response_time) by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course, this gives me back my nice pretty response when run in the web GUI, but in the SDK, I get an entry for each host, but hardly any mention of the other field.&lt;BR /&gt;
I've tried adding &lt;CODE&gt;|head&lt;/CODE&gt; and &lt;CODE&gt;|fields *&lt;/CODE&gt; and &lt;CODE&gt;| fields avg(response_time), host&lt;/CODE&gt; (that one actually changed the response string that comes back and gave me a new order. yay), as well as adding &lt;CODE&gt;response_time &amp;gt; 0&lt;/CODE&gt; to the end of the search string (winds up bringing back nothing for reasons I can't understand).&lt;/P&gt;

&lt;P&gt;I've looked at several other links that I can't link because you guys apparently don't accept reddit karma. But there were a bunch of suggested links when I made the title, and they were all purple.&lt;/P&gt;

&lt;P&gt;The field transformation that defines the field that I'm looking for is set to "Sharing: App" in the settings page. I'm not sure if that &lt;EM&gt;means&lt;/EM&gt; global, but the best permissions I can set are "everyone can read it". I can attempt to contact our admin with specific "set this to global" instructions if I can find them.&lt;/P&gt;

&lt;P&gt;I tried adding service.setNamespace to the application namespace that the field is defined in, it changed nothing.&lt;/P&gt;

&lt;P&gt;Edit: Just tried running the same query over the REST API (/search/jobs endpoint) and got back populated results, so I'm assuming it's not permissions and is rather an issue with how I'm using the code.&lt;BR /&gt;
I also tried "To run a normal search and poll for completion" section from &lt;A href="http://dev.splunk.com/view/java-sdk/SP-CAAAEHQ"&gt;http://dev.splunk.com/view/java-sdk/SP-CAAAEHQ&lt;/A&gt;&lt;BR /&gt;
which seems to be the closest thing in the Java SDK, and am getting the same results as previously mentioned.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 22:43:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249857#M74564</guid>
      <dc:creator>EricWehrly</dc:creator>
      <dc:date>2016-01-27T22:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249858#M74565</link>
      <description>&lt;P&gt;Could you post your source code, describe what results you get back and also describe what results you expect to get back?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 16:07:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249858#M74565</guid>
      <dc:creator>rfujara_splunk</dc:creator>
      <dc:date>2016-01-29T16:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249859#M74566</link>
      <description>&lt;P&gt;Can you try renaming the field in stats and try? Something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="[my_index]" sourcetype="[my_index]" | stats avg(response_time) as avg_response_time by host
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2016 16:16:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249859#M74566</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-01-29T16:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249860#M74567</link>
      <description>&lt;P&gt;Thanks for posting the search string!&lt;/P&gt;

&lt;P&gt;Could you also describe the result you get and also the result you expected to get? &lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 16:44:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249860#M74567</guid>
      <dc:creator>rfujara_splunk</dc:creator>
      <dc:date>2016-01-29T16:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249861#M74568</link>
      <description>&lt;P&gt;Yup, tried that. It changed the field names in the response header, but the result elements still only had host.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2016 18:27:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249861#M74568</guid>
      <dc:creator>EricWehrly</dc:creator>
      <dc:date>2016-01-29T18:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249862#M74569</link>
      <description>&lt;P&gt;For SDK code, I've been trying just about every example on the CAAAEHQ page. I have tried one-shot and export searches off of the service object, tweaking every parameter I could find.&lt;/P&gt;

&lt;P&gt;Currently, I'm attempting the following:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;private InputStream getSearchResults()&lt;BR /&gt;
{&lt;BR /&gt;
        String searchQuery_normal = "search index=\"[our_index]\"&lt;BR /&gt;
source=\"&lt;EM&gt;[our_source]&lt;/EM&gt;\" | stats&lt;BR /&gt;
avg(response_time) AS avg_resp_time by&lt;BR /&gt;
host | fields host, avg_resp_time ";&lt;BR /&gt;
        JobArgs jobargs = new JobArgs();&lt;BR /&gt;
        // jobargs.setExecutionMode(JobArgs.ExecutionMode.NORMAL);&lt;BR /&gt;
        jobargs.put("earliest_time", "-1h@h");&lt;BR /&gt;
        jobargs.put("latest_time", "now");&lt;BR /&gt;
        jobargs.setExecutionMode(JobArgs.ExecutionMode.BLOCKING);&lt;BR /&gt;
        Job job = service.getJobs().create(searchQuery_normal,&lt;BR /&gt;
jobargs);&lt;BR /&gt;
        while (!job.isDone()) {&lt;BR /&gt;
            try {&lt;BR /&gt;
                Thread.sleep(500);&lt;BR /&gt;
            } catch (InterruptedException e) {&lt;BR /&gt;
                // TODO Auto-generated catch block&lt;BR /&gt;
                e.printStackTrace();&lt;BR /&gt;
            }&lt;BR /&gt;
        }&lt;BR /&gt;
        System.out.println("Search job ID:         " + job.getSid());&lt;BR /&gt;
        return job.getResults();&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;If I curl the following URL, I get back a SID from the REST API:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;https://[ouraccount].splunkcloud.com:8089/servicesNS/[myusername]/atc_apps/search/jobs -d search="search index=[our_index] sourcetype=[our_sourcetype] earliest=\"-1h@h\" latest=\"now\" | stats avg(response_time) by host"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Using the REST API to compare responses, with the first SID, I get back XML response elements that contain a single field tag with a k value of host. With the latter SID, I get response elements that contain the desired two field tags; one host, and one avg(response_time)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:34:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249862#M74569</guid>
      <dc:creator>EricWehrly</dc:creator>
      <dc:date>2020-09-29T08:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249863#M74570</link>
      <description>&lt;P&gt;To me, this sounds like you are not running the search within the same application context.&lt;/P&gt;

&lt;P&gt;Either set the permissions for the "response_time" field extraction to global or make sure to set the search context to the correct application for both searches (web UI and Java SDK).&lt;/P&gt;

&lt;P&gt;That should solve your problem.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 20:46:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249863#M74570</guid>
      <dc:creator>rfujara_splunk</dc:creator>
      <dc:date>2016-02-01T20:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Java SDK: Why am I only getting one field with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249864#M74571</link>
      <description>&lt;P&gt;Setting the search context was a little tricky.&lt;/P&gt;

&lt;P&gt;It appears as though by default, any searches are executed as though in the splunk "search" application (/search/search in the rest API or web GUI).&lt;/P&gt;

&lt;P&gt;The context must be changed during initialization of the &lt;STRONG&gt;service&lt;/STRONG&gt; object.&lt;BR /&gt;
There is a method which takes a ServiceArgs object, and a method which takes a Map of String, Object. Even though the ServiceArgs one has explicit statements like "setHost", and fits the scheme of the rest of the API, it's marked as deprecated. Looking at the Map-based constructor provides all of the items it will digest. In order to set the app context, it was necessary for me to put the following keys:&lt;BR /&gt;
app, host, port.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 20:52:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Java-SDK-Why-am-I-only-getting-one-field-with-stats/m-p/249864#M74571</guid>
      <dc:creator>EricWehrly</dc:creator>
      <dc:date>2016-02-01T20:52:15Z</dc:date>
    </item>
  </channel>
</rss>

