<?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: smallest value in a multi value field splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414707#M119449</link>
    <description>&lt;P&gt;&lt;STRONG&gt;[UPDATED ANSWER]&lt;/STRONG&gt;&lt;BR /&gt;
Since min() on multi-valued field is applying lexicographical order (treating the numbers as string). &lt;BR /&gt;
One approach would be to pad zeros to the values using rex (I have added 10 zeros to example below, you can add/remove as per your needs). Then apply &lt;CODE&gt;min()&lt;/CODE&gt;. Finally, using ltrim() remove padded zeros from left.&lt;/P&gt;

&lt;P&gt;Please try out and confirm.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval h="10,9,70,100" 
| makemv delim="," h 
| rex mode=sed field=h "s/(\d+)/0000000000\1/"
| eval smallest=trim(min(h),"0")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;@nawazns5038  just pipe &lt;CODE&gt;| eval smallest=min(h)&lt;/CODE&gt; to your existing search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval h="1234,1" 
| makemv delim="," h
| eval smallest=min(h)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Jul 2019 23:11:46 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-07-25T23:11:46Z</dc:date>
    <item>
      <title>smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414706#M119448</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Does anybody know how to pull the smallest or the largest value in a multi value field ? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval h="1234,1" | makemv delim="," h 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want the output as the lowest of the values in the multi value field . that is "1"&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 22:54:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414706#M119448</guid>
      <dc:creator>nawazns5038</dc:creator>
      <dc:date>2019-07-25T22:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414707#M119449</link>
      <description>&lt;P&gt;&lt;STRONG&gt;[UPDATED ANSWER]&lt;/STRONG&gt;&lt;BR /&gt;
Since min() on multi-valued field is applying lexicographical order (treating the numbers as string). &lt;BR /&gt;
One approach would be to pad zeros to the values using rex (I have added 10 zeros to example below, you can add/remove as per your needs). Then apply &lt;CODE&gt;min()&lt;/CODE&gt;. Finally, using ltrim() remove padded zeros from left.&lt;/P&gt;

&lt;P&gt;Please try out and confirm.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval h="10,9,70,100" 
| makemv delim="," h 
| rex mode=sed field=h "s/(\d+)/0000000000\1/"
| eval smallest=trim(min(h),"0")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;@nawazns5038  just pipe &lt;CODE&gt;| eval smallest=min(h)&lt;/CODE&gt; to your existing search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval h="1234,1" 
| makemv delim="," h
| eval smallest=min(h)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 23:11:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414707#M119449</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-07-25T23:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414708#M119450</link>
      <description>&lt;P&gt;Hi @niketnilay , It does not work , please look into the following example and run the below query . I  think it sorts lexicographically &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval h="10, 9, 70, 100 " 
 | makemv delim="," h
 | eval smallest=max(h)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The query result would be 9 but not 100. The &lt;CODE&gt;min(h)&lt;/CODE&gt; would show as 10 instead of 9. &lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 00:10:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414708#M119450</guid>
      <dc:creator>nawazns5038</dc:creator>
      <dc:date>2019-07-26T00:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414709#M119451</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this, min and max in multi-value&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
 | eval test="10,5,6,1" 
 | makemv delim="," test 
 | stats min(test) as min max(test) as max
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2019 01:35:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414709#M119451</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-07-26T01:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414710#M119452</link>
      <description>&lt;P&gt;@nawazns5038 what is your existing query which gives you multivalue field? Is it because of stats or directly from your data or multi-valued field extraction like rex.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 02:46:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414710#M119452</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-07-26T02:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414711#M119453</link>
      <description>&lt;P&gt;Does not work,&lt;/P&gt;

&lt;P&gt;Try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
  | eval test="10, 9, 70, 100 " 
  | makemv delim="," test 
  | stats min(test) as min max(test) as max
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 19:12:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414711#M119453</guid>
      <dc:creator>nawazns5038</dc:creator>
      <dc:date>2019-07-29T19:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414712#M119454</link>
      <description>&lt;P&gt;@niketnilay , the values are coming from a lookup , so for one field value in splunk there are multiple matches and the matches come in a multivalue value after we do the lookup command , I want the lowest or the highest of the multivalue field values. &lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 20:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414712#M119454</guid>
      <dc:creator>nawazns5038</dc:creator>
      <dc:date>2019-07-29T20:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414713#M119455</link>
      <description>&lt;P&gt;This works for me to treat the results as numbers:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="10, 9, 70, 100" 
| makemv delim="," test

| rex field=test "(?&amp;lt;test_nums&amp;gt;\d+)"
| stats min(test_nums) as min
        max(test_nums) as max
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 20:45:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414713#M119455</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-07-29T20:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414714#M119456</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this, &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="10, 9, 70, 100 " 
| makemv delim="," test 
| eval test= trim(test) 
| stats min(test) as min max(test) as max
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 22:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414714#M119456</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-07-29T22:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414715#M119457</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | streamstats count AS _serial
| stats min(h) AS min_h max(h) AS max_h BY _serial
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You may have to add &lt;CODE&gt;makemv delim="," h&lt;/CODE&gt; to make &lt;CODE&gt;h&lt;/CODE&gt; truly mutlivalued.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 06:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414715#M119457</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-30T06:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414716#M119458</link>
      <description>&lt;P&gt;I think its the white space that's creating an issue.&lt;BR /&gt;
Try below&lt;/P&gt;

&lt;P&gt;| makeresults &lt;BR /&gt;
| eval h="10, 9, 70, 100" &lt;BR /&gt;
| rex mode=sed field=h "s/ //g" &lt;BR /&gt;
| makemv delim="," h &lt;BR /&gt;
| eval smallest=min(h)&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2019 06:18:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414716#M119458</guid>
      <dc:creator>chinmoya</dc:creator>
      <dc:date>2019-07-30T06:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: smallest value in a multi value field splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414717#M119459</link>
      <description>&lt;P&gt;@nawazns5038  have you tried the updated query?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearchReturningMultiValueField_h&amp;gt;
 | rex mode=sed field=h "s/(\d+)/0000000000\1/"
 | eval smallest=trim(min(h),"0")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2019 16:27:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/smallest-value-in-a-multi-value-field-splunk/m-p/414717#M119459</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-07-30T16:27:05Z</dc:date>
    </item>
  </channel>
</rss>

