<?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: Python SDK: search from job does not use all fields in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300491#M3865</link>
    <description>&lt;P&gt;Unfortunately, this did not help&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2018 12:09:25 GMT</pubDate>
    <dc:creator>ksander14</dc:creator>
    <dc:date>2018-01-11T12:09:25Z</dc:date>
    <item>
      <title>Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300489#M3863</link>
      <description>&lt;P&gt;I have some source named "source1" with field named "field1". This field is not present in all events (field is filled only in 3 percent of events). So, I try to get events with this field using Splunk Python SDK using simple construction from documentation.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;search_text = "source=source1 field1=* earliest=-1d@d latest=@d"&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;job = jobs.create(search_text)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;while True:&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;while not job.is_ready():&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;pass&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;stats = {"isDone": job["isDone"],&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;"doneProgress": float(job["doneProgress"])*100,&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;"scanCount": int(job["scanCount"]),&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;"eventCount": int(job["eventCount"]),&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;"resultCount": int(job["resultCount"])}&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;status = ("\r%(doneProgress)03.1f%%   %(scanCount)d scanned   "&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;"%(eventCount)d matched   %(resultCount)d results") % stats&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sys.stdout.write(status)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sys.stdout.flush()&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;if stats["isDone"] == "1":&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sys.stdout.write("\n\nDone!\n\n")&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;break&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sleep(2)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;But this search, run using Splunk Python SDK, return me 0 results. If I run this search in Splunk, I get right results - events with filled "field1". So, as I understand this situation, search in Splunk Python SDK doesn't see "field1" in my source.&lt;/P&gt;

&lt;P&gt;How can I run search with Spunk Python SDK that see all fields in my source?&lt;/P&gt;

&lt;P&gt;P.S. For example - if I run "search source=source1 earliest=-1d@d latest=@d | fieldsummary" in Splunk, I get information about 84 fields, in Splunk Python SDK - 81 fields&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 12:50:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300489#M3863</guid>
      <dc:creator>ksander14</dc:creator>
      <dc:date>2018-01-10T12:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300490#M3864</link>
      <description>&lt;P&gt;Change your search string in the script to &lt;CODE&gt;search source=source1 field1=* earliest=-1d@d latest=@d&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The REST API, which the SDK uses, does not add the implied &lt;CODE&gt;search&lt;/CODE&gt; command to the front of your search strings like the UI does.&lt;/P&gt;

&lt;P&gt;Also, add &lt;CODE&gt;| fields &amp;lt;field1&amp;gt; &amp;lt;field2&amp;gt;&lt;/CODE&gt;.  This should ensure that Splunk grabs the fields you care about, even if running in fast mode (which may be what is happening here).&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:34:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300490#M3864</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-10T15:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300491#M3865</link>
      <description>&lt;P&gt;Unfortunately, this did not help&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 12:09:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300491#M3865</guid>
      <dc:creator>ksander14</dc:creator>
      <dc:date>2018-01-11T12:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300492#M3866</link>
      <description>&lt;P&gt;Updated answer to include &lt;CODE&gt;fields&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 15:12:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300492#M3866</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-11T15:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300493#M3867</link>
      <description>&lt;P&gt;Thanks for the advice, but it did not help &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 09:11:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300493#M3867</guid>
      <dc:creator>ksander14</dc:creator>
      <dc:date>2018-01-12T09:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300494#M3868</link>
      <description>&lt;P&gt;Hi, I have the same problem.&lt;BR /&gt;
I've updated the search to be &lt;CODE&gt;search index=alfa | fields field1, field2&lt;/CODE&gt;. Also tried adding the &lt;CODE&gt;rf&lt;/CODE&gt; field in &lt;CODE&gt;search_kwargs&lt;/CODE&gt;, but still these fields are not returned, so my search returns no results (although there are of course results).&lt;/P&gt;

&lt;P&gt;The code looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search_kwargs = {
            "exec_mode": "normal",
            "earliest_time": "-8d",
            "latest_time": "now",
            "search_mode": "normal",
            "rf": ["field1", "field2"],
}
search = "search index=alfa | fields field1, field2"
job = jobs.create(search, **search_kwargs)
# Then pool for job completion, and list results....
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2018 15:27:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300494#M3868</guid>
      <dc:creator>burtica</dc:creator>
      <dc:date>2018-01-12T15:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300495#M3869</link>
      <description>&lt;P&gt;Hi, I have the same problem.&lt;BR /&gt;
I have also added the fields in the &lt;CODE&gt;rf&lt;/CODE&gt; field of the &lt;CODE&gt;search_kwargs&lt;/CODE&gt; as below, but still I am not returned any data, although there is data. The fields &lt;CODE&gt;field1&lt;/CODE&gt; and &lt;CODE&gt;field2&lt;/CODE&gt; are actually not returned. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search_kwargs = {
            "exec_mode": "normal",
            "earliest_time": "-8d",
            "latest_time": "now",
            "search_mode": "normal",
            "rf": ["field1", "field2"],
}
search = "search index=alfa | fields field1, field2"
job = jobs.create(search, **search_kwargs)
# Then pool for job completion, and list results....
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2018 15:30:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300495#M3869</guid>
      <dc:creator>burtica</dc:creator>
      <dc:date>2018-01-12T15:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python SDK: search from job does not use all fields</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300496#M3870</link>
      <description>&lt;P&gt;How is &lt;CODE&gt;field1&lt;/CODE&gt; defined? Is it a custom extraction you put in place?  Is it shared globally?&lt;/P&gt;

&lt;P&gt;Is the account you're using to log in to SplunkWeb the same account you're using for the python script?&lt;/P&gt;

&lt;P&gt;I put your code into a python script and it seems to work just fine (I removed the timeframe from the search string for mine):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search_text = "search source=source1 field1=*"
job = service.jobs.create(search_text)
while True:
    while not job.is_ready():
            pass
    stats = {"isDone": job["isDone"],
        "doneProgress": float(job["doneProgress"])*100,
        "scanCount": int(job["scanCount"]),
        "eventCount": int(job["eventCount"]),
        "resultCount": int(job["resultCount"])}
    status = ("\r%(doneProgress)03.1f%% %(scanCount)d scanned "
        "%(eventCount)d matched %(resultCount)d results") % stats
    sys.stdout.write(status)
    sys.stdout.flush()
    if stats["isDone"] == "1":
        sys.stdout.write("\n\nDone!\n\n")
        break
    sleep(2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2018 16:29:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-SDK-search-from-job-does-not-use-all-fields/m-p/300496#M3870</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-01-12T16:29:56Z</dc:date>
    </item>
  </channel>
</rss>

