<?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: Is there a way to check if a value is between a list of values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376469#M110527</link>
    <description>&lt;P&gt;Hey, this solution still will not work because say a value is between the ranges it will still get selected I believe. &lt;/P&gt;</description>
    <pubDate>Tue, 18 Sep 2018 15:08:33 GMT</pubDate>
    <dc:creator>charlesmcdonald</dc:creator>
    <dc:date>2018-09-18T15:08:33Z</dc:date>
    <item>
      <title>Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376463#M110521</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;

&lt;P&gt;Is there a way to check if a number is between a list of ranges in a multi value field?&lt;/P&gt;

&lt;P&gt;For example on this table, I would want to create a new true/false field based on if "Value" is between one of the values in the Ranges column. I know this should be possible with &lt;CODE&gt;mvexpand&lt;/CODE&gt; but that would get quite verbose especially if there were multiple sets of Ranges. &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5778iDC30A0ADD219396A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I tried looking but I couldn't find a 'for each' equivalent for multi value fields though maybe there is something I missed.&lt;/P&gt;

&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 17:33:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376463#M110521</guid>
      <dc:creator>charlesmcdonald</dc:creator>
      <dc:date>2018-09-17T17:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376464#M110522</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I've found a way to do this but I'm making some assumptions. This method works if your "Ranges" values always come in sets of threes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 1 
| eval ID="0001",Ranges="1536609307-1536609307,1536782107-1536782107,1536868507-1536868507",Value="1536682105" 
| makemv delim="," Ranges
| eval first_value=mvindex(Ranges,0),last_value=mvindex(Ranges,2)
| eval first_value=replace(first_value,"\-\d+","")
| eval last_value=replace(last_value,"\-\d+","") 
| where Value &amp;gt; first_value AND Value &amp;lt; last_value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We're using mvindex to create separate values for your first and last value and then the replace function to make it numerically searchable. After that, we just compare "Value" against the first and last value from your range.&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:32:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376464#M110522</guid>
      <dc:creator>zonistj</dc:creator>
      <dc:date>2018-09-17T18:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376465#M110523</link>
      <description>&lt;P&gt;Hey thanks for the response, unfortunately my ranges can be anywhere from 0 to 50 values so this will not work. Additionally, they may not be continuous so only looking if the number is between the first start and the last end may miss some values.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 18:45:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376465#M110523</guid>
      <dc:creator>charlesmcdonald</dc:creator>
      <dc:date>2018-09-17T18:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376466#M110524</link>
      <description>&lt;P&gt;Thanks for the additional information. I can help with the first issue :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 1 
| eval ID="0001",Ranges="1536609307-1536609307,1536782107-1536782107,1536868507-1536868507",Value="1536682105" 
| fields - count 
| makemv delim="," Ranges
**| eval test_count = mvcount(Ranges)-1**
| eval first_value=mvindex(Ranges,0),last_value=**mvindex(Ranges,test_count)**
| eval first_value=replace(first_value,"\-\d+","")
| eval last_value=replace(last_value,"\-\d+","") 
| where Value &amp;gt; first_value AND Value &amp;lt; last_value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;By using the "mvcount" function, we can dynamically set our mvindex to the last value regardless if it's 3 or 50.&lt;/P&gt;

&lt;P&gt;I'm not sure if we can get around the other issue of the data not being continuous.  It seems like that's a data source issue that is in contradiction to your use case. If possible, it's best to address that upstream at the data source.&lt;/P&gt;

&lt;P&gt;But we might be able to do something. Can you post an example of what the non-continuous data looks like?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 19:21:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376466#M110524</guid>
      <dc:creator>zonistj</dc:creator>
      <dc:date>2018-09-17T19:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376467#M110525</link>
      <description>&lt;P&gt;The original example I posted is non-continuous, but another example of values that could be in Range would be: '1536695705-1536868507, 1536954904-1537214108'&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 20:14:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376467#M110525</guid>
      <dc:creator>charlesmcdonald</dc:creator>
      <dc:date>2018-09-17T20:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376468#M110526</link>
      <description>&lt;P&gt;Okay, I think this will work but it might not perform quickly depending on your volume of data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 1 
| eval ID="0001",Ranges="1536695705-1536868507,1536954904-1537214108",Value="1536702105" 
| fields - count 
| makemv delim="," Ranges
| rex field=Ranges "(?&amp;lt;first_value&amp;gt;\d+)\-(?&amp;lt;last_value&amp;gt;\d+)"
| mvexpand first_value
| mvexpand last_value
| stats values(Value) AS Value  by ID,first_value,last_value
| where Value &amp;gt; first_value AND Value &amp;lt; last_value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I still think this could be best solved upstream. You might be able to get clever with transforms.conf and extract the necessary fields out at index time.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 20:53:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376468#M110526</guid>
      <dc:creator>zonistj</dc:creator>
      <dc:date>2018-09-17T20:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376469#M110527</link>
      <description>&lt;P&gt;Hey, this solution still will not work because say a value is between the ranges it will still get selected I believe. &lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 15:08:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376469#M110527</guid>
      <dc:creator>charlesmcdonald</dc:creator>
      <dc:date>2018-09-18T15:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376470#M110528</link>
      <description>&lt;P&gt;You're right. This mvexpand technique results in the first and last values for each range on the same lines. I'll work on it further and see if I can figure something out. Thanks for the interesting problem!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 15:44:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376470#M110528</guid>
      <dc:creator>zonistj</dc:creator>
      <dc:date>2018-09-18T15:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376471#M110529</link>
      <description>&lt;P&gt;Oh, here, it occurred to me that we could just do the mvexpand before rex'ing out the new fields. That should solve the issue:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 1 
| eval ID="0001",Ranges="1536695705-1536868507,1536954904-1537214108",Value="1536702105" 
| fields - count 
| makemv delim="," Ranges 
| mvexpand Ranges 
| rex field=Ranges "(?&amp;lt;first_value&amp;gt;\d+)\-(?&amp;lt;last_value&amp;gt;\d+)" 
| stats values(Value) AS Value by ID,first_value,last_value 
| where Value &amp;gt; first_value AND Value &amp;lt; last_value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you take out the final "where" statement, you'll see that all of your ranges are there, but only the ones that have "value" in the range show in the results with the "where" statement.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 15:45:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376471#M110529</guid>
      <dc:creator>zonistj</dc:creator>
      <dc:date>2018-09-18T15:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check if a value is between a list of values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376472#M110530</link>
      <description>&lt;P&gt;Okay this might work, will have to play around with it to see if there are any ways to speed it up since I'm looking at 10 mil+ rows. &lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 16:03:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-check-if-a-value-is-between-a-list-of-values/m-p/376472#M110530</guid>
      <dc:creator>charlesmcdonald</dc:creator>
      <dc:date>2018-09-18T16:03:44Z</dc:date>
    </item>
  </channel>
</rss>

