<?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 How do I translate a GUI search query into a python API query? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432979#M7771</link>
    <description>&lt;P&gt;newbie question...&lt;BR /&gt;
I'd like to know the appropriate Python API syntax for the following GUI query:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;source="/var/log/my-test.log" index="testing" sourcetype="_json"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I get a good set of results running it in the GUI but I'm always getting 0 results from the API. I'm working off the API docs with the following base code:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;kwargs_blockingsearch = {"exec_mode": "blocking"}&lt;BR /&gt;
searchquery_blocking = "search * | head 10"&lt;BR /&gt;
job = jobs.create(searchquery_blocking, **kwargs_blockingsearch)&lt;BR /&gt;
so...&lt;BR /&gt;
what's the correct syntax for replacing "search *|head 10" with my query?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Wed, 30 Sep 2020 01:38:36 GMT</pubDate>
    <dc:creator>lfast12</dc:creator>
    <dc:date>2020-09-30T01:38:36Z</dc:date>
    <item>
      <title>How do I translate a GUI search query into a python API query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432979#M7771</link>
      <description>&lt;P&gt;newbie question...&lt;BR /&gt;
I'd like to know the appropriate Python API syntax for the following GUI query:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;source="/var/log/my-test.log" index="testing" sourcetype="_json"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I get a good set of results running it in the GUI but I'm always getting 0 results from the API. I'm working off the API docs with the following base code:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;kwargs_blockingsearch = {"exec_mode": "blocking"}&lt;BR /&gt;
searchquery_blocking = "search * | head 10"&lt;BR /&gt;
job = jobs.create(searchquery_blocking, **kwargs_blockingsearch)&lt;BR /&gt;
so...&lt;BR /&gt;
what's the correct syntax for replacing "search *|head 10" with my query?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:38:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432979#M7771</guid>
      <dc:creator>lfast12</dc:creator>
      <dc:date>2020-09-30T01:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I translate a GUI search query into a python api query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432980#M7772</link>
      <description>&lt;P&gt;@lfast12 &lt;/P&gt;

&lt;P&gt;Just replace it with your search.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;searchquery_blocking = 'search  source="/var/log/my-test.log" index="testing" sourcetype="_json" '&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;searchquery_blocking = "search source=\"/var/log/my-test.log\" index=\"testing\" sourcetype=\"_json\" '&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;Check section &lt;STRONG&gt;To create a blocking search and display properties of the job&lt;/STRONG&gt; in below link.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEE5"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEE5&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 04:39:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432980#M7772</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-08-06T04:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I translate a GUI search query into a python api query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432981#M7773</link>
      <description>&lt;P&gt;Thanks Kamlesh,&lt;BR /&gt;
That didn't work but it put me on the right track.  Here's what finally worked:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;kwargs_blockingsearch = {"exec_mode": "blocking"}&lt;BR /&gt;
searchquery_blocking = 'search source="/var/log/splunk-test.log" index="testing" sourcetype="_json"'&lt;BR /&gt;
job = jobs.create(searchquery_blocking, **kwargs_blockingsearch)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The only difference is prefixing your suggestion with 'search ...'&lt;/P&gt;

&lt;P&gt;Simple enough but when there are too many choices you can easily go down the wrong path.  Thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432981#M7773</guid>
      <dc:creator>lfast12</dc:creator>
      <dc:date>2020-09-30T01:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I translate a GUI search query into a python api query?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432982#M7774</link>
      <description>&lt;P&gt;@lfast12&lt;/P&gt;

&lt;P&gt;Yes.  I missed adding the &lt;CODE&gt;search&lt;/CODE&gt; command. Updated answer.  When we execute any search from Python or CURL we need to add &lt;CODE&gt;search&lt;/CODE&gt; initially which is not required in GUI.  Please upvote and accept this answer if it helps you.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 06:31:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-translate-a-GUI-search-query-into-a-python-API-query/m-p/432982#M7774</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-08-06T06:31:26Z</dc:date>
    </item>
  </channel>
</rss>

