<?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 can I do a basic &amp;quot;IN&amp;quot; command  in Splunk? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380326#M166682</link>
    <description>&lt;P&gt;@hanriv0001, try the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype= Order product_id IN 
    [ search host=product
    | stats values(product_number) as product_number
    | eval product_number="(\"".replace(mvjoin(product_number,","),",","\",\"")."\")"
    | rename product_number as search] 
| stats count by order_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere example based on Splunk's _internal index, on lines similar to above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level IN 
    [ search index=_internal sourcetype=splunkd 
    | stats values(log_level) as log_level 
    | eval log_level="(\"".replace(mvjoin(log_level,","),",","\",\"")."\")"
    | rename log_level as search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based on your use case, ideally, you should be trying the following approach using format command rather than IN clause,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=Order 
    [ search host=product
    | dedup product_number
    | rename product_number as product_id
    | format] 
| stats count by order_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on Splunk's _internal index on lines similar to example above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd 
    [ search index=_internal sourcetype=splunkd 
    | dedup log_level 
    | table log_level 
    | format ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Nov 2018 19:04:14 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-11-08T19:04:14Z</dc:date>
    <item>
      <title>How can I do a basic "IN" command  in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380325#M166681</link>
      <description>&lt;P&gt;I am trying to accomplish a simple "IN" command in Splunk, basically by filtering the result to show only those entries which have an entry for their "product_id" number in a another tables "product_number" attribute.&lt;/P&gt;

&lt;P&gt;But Splunk throws an error saying: "Error in 'search' command: Unable to parse the search: Comparator 'IN' has an invalid term on the right hand side: NOT"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype= Order  product_id IN [ search host=product | table product_number] | stats count by order_id 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any help in understanding what I am doing wrong would be of great.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:56:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380325#M166681</guid>
      <dc:creator>hanriv0001</dc:creator>
      <dc:date>2020-09-29T21:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a basic "IN" command  in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380326#M166682</link>
      <description>&lt;P&gt;@hanriv0001, try the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype= Order product_id IN 
    [ search host=product
    | stats values(product_number) as product_number
    | eval product_number="(\"".replace(mvjoin(product_number,","),",","\",\"")."\")"
    | rename product_number as search] 
| stats count by order_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere example based on Splunk's _internal index, on lines similar to above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level IN 
    [ search index=_internal sourcetype=splunkd 
    | stats values(log_level) as log_level 
    | eval log_level="(\"".replace(mvjoin(log_level,","),",","\",\"")."\")"
    | rename log_level as search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based on your use case, ideally, you should be trying the following approach using format command rather than IN clause,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=Order 
    [ search host=product
    | dedup product_number
    | rename product_number as product_id
    | format] 
| stats count by order_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on Splunk's _internal index on lines similar to example above:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd 
    [ search index=_internal sourcetype=splunkd 
    | dedup log_level 
    | table log_level 
    | format ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Nov 2018 19:04:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380326#M166682</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-11-08T19:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a basic "IN" command  in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380327#M166683</link>
      <description>&lt;P&gt;@niketnilay I tried both the approaches but to no avail. &lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 20:28:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380327#M166683</guid>
      <dc:creator>hanriv0001</dc:creator>
      <dc:date>2018-11-08T20:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a basic "IN" command  in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380328#M166684</link>
      <description>&lt;P&gt;Its the way the sub-search returns the result is the problem&lt;BR /&gt;
It returns a key value pair which like "(product_number = " 123") OR (product_number = " 345")"&lt;BR /&gt;
which destroys the syntax for the IN clause. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:56:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380328#M166684</guid>
      <dc:creator>hanriv0001</dc:creator>
      <dc:date>2020-09-29T21:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a basic "IN" command  in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380329#M166685</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/149915"&gt;@hanriv0001&lt;/a&gt; , two things which you missed in the second answer:&lt;/P&gt;

&lt;P&gt;1) &lt;CODE&gt;| rename product_number as product_id&lt;/CODE&gt; ensures that format command prepares search filter as &lt;CODE&gt;(product_id = " 123") OR (product_id = " 345")&lt;/CODE&gt; and not that with product_name.&lt;/P&gt;

&lt;P&gt;2) Since the filters are prepared as several OR conditions you don't need &lt;CODE&gt;product_id IN&lt;/CODE&gt; in your search.&lt;/P&gt;

&lt;P&gt;PS: If you want to use &lt;CODE&gt;product_id IN&lt;/CODE&gt; in your main search, you would need to prepare comma separated values  like &lt;CODE&gt;("123","345")&lt;/CODE&gt;. For which option 1 should work.&lt;/P&gt;

&lt;P&gt;Have you tried the run anywhere searches? The values of log_level in _internal index can be INFO ERROR or WARN. So you can append &lt;CODE&gt;| stats count by log_level&lt;/CODE&gt; to any of your searches to test the same.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:01:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380329#M166685</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T22:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a basic "IN" command  in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380330#M166686</link>
      <description>&lt;P&gt;Thank you, that works &lt;BR /&gt;
I really appreciate your help with this. &lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 22:18:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-basic-quot-IN-quot-command-in-Splunk/m-p/380330#M166686</guid>
      <dc:creator>hanriv0001</dc:creator>
      <dc:date>2018-11-08T22:18:14Z</dc:date>
    </item>
  </channel>
</rss>

