<?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: Can I save mvexpand when matching a multivalue lookup? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556369#M158000</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One crazy solution is to use mvzip() to "tie" those potentially multivalue fields together, perform the match against tied string (considerations in not create false matches, too), then split the matched jumbo string to return text, date in the match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval crazymv = mvzip(text, date, "|:crazy:|"),
crazymatch = mvfind(crazymv, "abc"),
crazysv = mvindex(crazymv, crazymatch)
crazysplit = split(crazysv, "|:crazy:|"), 1),
text = mvindex(crazysplit, 0),
date = mvindex(crazysplit, 1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Jun 2021 01:59:52 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2021-06-19T01:59:52Z</dc:date>
    <item>
      <title>Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556364#M157996</link>
      <description>&lt;P&gt;I have a lookup that can return multivalue for two fields, one of them a timestamp, like this&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;key&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;text&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;key1&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;abc|def&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;2021-04-06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;key1&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;efg|hij&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;2021-06-04&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;A lookup on key1 will return&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;key&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;text&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;key1&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;P&gt;abc|def&lt;/P&gt;&lt;P&gt;efg|hij&lt;/P&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;P&gt;2021-04-06&lt;/P&gt;&lt;P&gt;2021-12-31&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I then want to match the text field as regex, and perform calculation on the matching date. &amp;nbsp;For example,&amp;nbsp;match(text, mytext) where mytext = "abc", and compare now() &amp;gt; strptime(date, "%Y-%m-%d").&lt;/P&gt;&lt;P&gt;I saw many mvexpand solutions in the past, and some mvjoin() solution. &amp;nbsp;mvexpand is expensive for my data, and mvjoin() only works for regex on text.&lt;/P&gt;&lt;P&gt;Is there some way to do this without mvexpand?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 22:20:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556364#M157996</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-18T22:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556366#M157997</link>
      <description>&lt;P&gt;Can you mvzip text and date, then mvmap the zipped field where the function uses the two halves for a match and date comparison?&lt;/P&gt;&lt;P&gt;In what way is mvexpand "expensive"? If you need an alternative to mvexpand, I posted a solution &lt;A href="http://%20https://community.splunk.com/t5/Splunk-Search/mvexpand-limits/m-p/549178" target="_self"&gt;here&lt;/A&gt;, although this was more to do with avoiding the limitations of mvexpand and may be just as "expensive" in your case as there are a lot of steps involved to perform the same action, but it does have the benefit of being able to expand more than one field at the same time.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 22:51:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556366#M157997</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-18T22:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556369#M158000</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One crazy solution is to use mvzip() to "tie" those potentially multivalue fields together, perform the match against tied string (considerations in not create false matches, too), then split the matched jumbo string to return text, date in the match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval crazymv = mvzip(text, date, "|:crazy:|"),
crazymatch = mvfind(crazymv, "abc"),
crazysv = mvindex(crazymv, crazymatch)
crazysplit = split(crazysv, "|:crazy:|"), 1),
text = mvindex(crazysplit, 0),
date = mvindex(crazysplit, 1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 01:59:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556369#M158000</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-19T01:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556370#M158001</link>
      <description>&lt;P&gt;Yes, mvzip(), then unzip (split()) is what I ended up doing. &amp;nbsp;The whole operation feels crazy.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;In what way is mvexpand "expensive"? If you need an alternative to mvexpand, I posted a solution &lt;A href="http://%20https://community.splunk.com/t5/Splunk-Search/mvexpand-limits/m-p/549178" target="_self"&gt;here&lt;/A&gt;, although this was more to do with avoiding the limitations of mvexpand and may be just as "expensive" in your case as there are a lot of steps involved to perform the same action, but it does have the benefit of being able to expand more than one field at the same time.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;mvexpand multiples total number of events down the stream. &amp;nbsp;In my example, there will be 4x original events. &amp;nbsp;BTW, that link is broken.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 01:58:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556370#M158001</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-19T01:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556372#M158003</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;mvexpand multiples total number of events down the stream. &amp;nbsp;In my example, there will be 4x original&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I had thought that if I did mvexpand in a subsearch that had very few events, or even just synthetic events, but incorporated the lookup, mvexpand would be cheap inside. &amp;nbsp;But I couldn't figure out how to make it do what I wanted. &amp;nbsp;The mvzip() method was from a long time ago, but isn't very SPL-like.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 02:23:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556372#M158003</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-19T02:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556382#M158005</link>
      <description>&lt;P&gt;Try this address&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/mvexpand-limits/m-p/549178" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/mvexpand-limits/m-p/549178&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 12:54:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556382#M158005</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-19T12:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556386#M158007</link>
      <description>&lt;P&gt;Here is a runanywhere example - the first part sets up some dummy data with different combinations of text and dates; the second part effectively is the results of the lookup (and should be replaced with the real lookup; and, the last part does the mvzip and mvmap to process the matching to return which entry matched the text and date.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval field=split("abc123,def234,cde345,abcdef987,efg234,abchij",",")
| mvexpand field
| eval time=split("2021-04-05,2021-04-06,2021-06-04,2021-06-05",",")
| mvexpand time


| appendcols 
    [| makeresults 
    | eval _raw="key	text	date
key1	abc|def	2021-04-06
key1	efg|hij	2021-06-04"
    | multikv forceheader=1
    | fields - _* linecount
    | stats list(*) as * by key]
| filldown key text date


| eval comb=mvzip(text,date,",")
| eval match=mvmap(comb,if(match(field,mvindex(split(comb,","),0)),if(time=mvindex(split(comb,","),1),comb,null),null))
| table time field key text date comb match&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 19 Jun 2021 14:26:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556386#M158007</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-19T14:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556393#M158008</link>
      <description>&lt;P&gt;So, this solution took two elements &amp;nbsp;that I wasn't &amp;nbsp;familiar.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;appendcols - compared to mvexpand, it doesn't increase number of events.&lt;/LI&gt;&lt;LI&gt;mvmap() - an enumerable feature in many languages that skipped my mind when you first mentioned it. Much cleaner than the crazy mvindex(), split() sequence that I had used.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;To illustrate in pseudo code,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;`THE search to return key and textfield for matching lookup`

| appendcols [
  lookup key_text_date key
]
| filldown key text date

| eval comb=mvzip(text, date, ",")
| eval match=mvmap(comb, if(match(textfield, mvindex(split(comb, ","), 0)), if(time=mvindex(split(comb, ","), 1), comb, null), null))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the &amp;nbsp;SPLeque solution I am looking for. &amp;nbsp;Thanks,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 00:17:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556393#M158008</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-20T00:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556394#M158009</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;To illustrate in pseudo code,&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| eval match=mvmap(comb, if(match(textfield, mvindex(split(comb, ","), 0)), if(time=mvindex(split(comb, ","), 1), comb, null), null))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Mmm I didn't inspect the code close enough. &amp;nbsp; The last piece &amp;nbsp;tries to match a nonexistent "time" &amp;nbsp;field with &amp;nbsp;the &amp;nbsp;date field from lookup. &amp;nbsp;The real use case of the date field is to be compared with something, not a precise match. &amp;nbsp; `THE Search to return key and textfield for matching lookup` only returns "key" to match the exact "key" in lookup, and a "textfield" to be matched as regex against "text" in lookup. &amp;nbsp; Like so&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=4
| eval keyfield="key1", textfield=split("abc123,def234,cde345,abcdef987,efg234,abchij",",")
| mvexpand textfield
| streamstats count
| eval _time=_time - count * 864000&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"date" in lookup is not used for matching events, but for comparison or other purposes, e.g., comparison and display.&lt;/P&gt;&lt;P&gt;As such, the general method of using mvzip - mvmap still stands, although another split is warranted to extract matching "date" for display purposes. (I'll use comparison _time &amp;lt;date as matching criterion in this illustration, although it can be any operation.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;`THE search to return key and textfield for matching lookup`

| lookup key_text_date key

| eval comb=mvzip(text, date, ",")
| eval match=mvmap(comb,
 if(match(textfield, mvindex(split(comb, ","), 0)),
 if(_time &amp;lt; strptime(mvindex(split(comb, ","), 1), "%Y-%m-%d"), comb, null), null)
)
| eval date = mvindex(split(match, ","), 1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I also realize that appendcol is just to simulate lookup; lookup effectively appends columns to search results.) &amp;nbsp; If I need matching text value for display, another mvindex() will be needed. &amp;nbsp;The code will look similarly complex, but this solution doesn't require consideration for &amp;nbsp;the mvjoin() and split() delimiter.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 20:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556394#M158009</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-20T20:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556398#M158011</link>
      <description>&lt;P&gt;Yes, the first part of my solution is replaced by your search, the second part is replaced by your lookup, the third part is modified to fit the comparisons you need in your specific use case. Sometimes, it is better to leave you with something to do, to give you an opportunity to understand the concepts behind the solution.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 07:57:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556398#M158011</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-06-20T07:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can I save mvexpand when matching a multivalue lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556427#M158024</link>
      <description>&lt;BLOCKQUOTE&gt;(I'll use comparison _time &amp;lt;date as matching criterion in this illustration, although it can be any operation.)&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval match=mvmap(comb,
 if(match(textfield, mvindex(split(comb, ","), 0)),
 if(_time &amp;lt; strptime(mvindex(split(comb, ","), 1), "%Y-%m-%d"), comb, null), null)
)
| eval date = mvindex(split(match, ","), 1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Note on application: Sometimes it is better to leave the operation on date out of mvmap() altogether; instead, perform that operation AFTER obtaining single-value "date" field. &amp;nbsp;This can be important if you are using flexible selectors in a dashboard. &amp;nbsp;In fact, the resultant code is outright more readable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;`THE search to return key and textfield for matching lookup`
| lookup key_text_date key

| eval comb=mvzip(text, date, ",")
| eval textmatch=mvmap(comb, if(match(textfield, mvindex(split(comb, ","), 0)), comb, null))
| eval date = mvindex(split(textmatch, ","), 1)
| eval fullmatch=if(_time &amp;lt; strptime(date, "%Y-%m-%d"), "yes", null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(One more note on syntax. &amp;nbsp;I have gotten into the habit of using null() in evals, not realizing that a side effect of SPL syntax makes unquoted token "null" equivalent to null(). &amp;nbsp;Of course, using side effect has its side effects. &amp;nbsp;The unquoted token may as well be "full" and it will still be interpreted as null(); e.g., the last eval above can be written as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval fullmatch=if(_time &amp;lt; strptime(date, "%Y-%m-%d"), "yes", yes)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and remains semantically identical.)&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 19:14:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-save-mvexpand-when-matching-a-multivalue-lookup/m-p/556427#M158024</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2021-06-20T19:14:36Z</dc:date>
    </item>
  </channel>
</rss>

