<?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: make multivalue field from job ID matching multiple customer IDs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522123#M147213</link>
    <description>&lt;P&gt;Ah yes, understood.&lt;/P&gt;&lt;P&gt;MV fields are sort of weird little things in Splunk-land.&amp;nbsp; I love 'em, they're really useful, but they sometimes behave in a way common sense would say they shouldn't.&amp;nbsp;&amp;nbsp; On the other hand, I think it's mostly sensible. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So!&amp;nbsp; Maybe a tiny pointer to help with understanding, and maybe how to play with some mv fields.&lt;/P&gt;&lt;P&gt;One thing we find ourselves doing a lot of, in order to create a run-anywhere search for examples here in Answers and in Slack, is something like the following.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval dates="2020-04-18:2 2020-04-24:5 2020-05-02:9 2020-05-09:7 2020-05-16:11 2020-05-23:8 2020-05-30:11 2020-06-06:9 2020-06-13:14" 
| makemv delim=" " dates 
| mvexpand dates 
| makemv delim=":" dates 
| eval date=mvindex(dates,0), count=mvindex(dates,1) 
| eval _time = strptime(date, "%Y-%m-%d") &lt;/LI-CODE&gt;&lt;P&gt;The explanation may give you a kick start here.&lt;/P&gt;&lt;P&gt;Do note, you can - and I recommend! - running this by starting with the first line, then add the second and run it again, and so on.&amp;nbsp; That way you can see each line and what it does to the previous results.&lt;/P&gt;&lt;P&gt;makeresults generates an empty event.&lt;/P&gt;&lt;P&gt;The eval just creates a simple field called "dates" with that big string in it.&lt;/P&gt;&lt;P&gt;We then make the field "dates" into a multi-valued field by splitting it on spaces.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that it's an mv field, we can 'mvexpand' it into separate events so now I have a series of precise dates&amp;nbsp; in the events.&lt;/P&gt;&lt;P&gt;Now comes the fun!&amp;nbsp; Now we make the new split-up field into a mv field by telling it to split it on the colon.&lt;/P&gt;&lt;P&gt;We don't actually want to expand that again, because then we'd have dates and "counts" on separate events.&amp;nbsp; Instead, we use mvindex() to pull out the first mv-value of the mv-field dates and call it 'date', and again pull out a count from the second mv-value of the mv-field.&lt;/P&gt;&lt;P&gt;Then last I set _time to be that date we pulled out.&lt;/P&gt;&lt;P&gt;So, that's just a bit of playing around with MV stuff, thought you might find it fun or at least useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For what it's worth, that search was a run anywhere I created to illustrate the bug that if the Splunk command "predict" is fed data where it has empty "left side" data (e.g. earlier), then it goofs up the graphs.&lt;/P&gt;&lt;P&gt;It's pretty funny and if you trendline some data with smoothing it over 5 periods or something (sma5) before predicting it...&lt;/P&gt;&lt;P&gt;You can see it for yourself.&amp;nbsp; Take the whole search below&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval dates="2020-04-18:2 2020-04-24:5 2020-05-02:9 2020-05-09:7 2020-05-16:11 2020-05-23:8 2020-05-30:11 2020-06-06:9 2020-06-13:14" 
| makemv delim=" " dates 
| mvexpand dates 
| makemv delim=":" dates 
| eval date=mvindex(dates,0), count=mvindex(dates,1) 
| eval _time = strptime(date, "%Y-%m-%d") 
| timechart sum(count) as count span=1w 
| trendline sma5(count) as smooth_count 
| predict smooth_count
| fields - smooth_count count&lt;/LI-CODE&gt;&lt;P&gt;Then change to the Visualization tab, then switch it to a line chart.&amp;nbsp; Follow the prediction line carefully...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Super fun.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:16:08 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2020-09-30T00:16:08Z</dc:date>
    <item>
      <title>make multivalue field from job ID matching multiple customer IDs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522065#M147196</link>
      <description>&lt;P&gt;In events that we extract CID and JID from, I would like to have an output of all JID that interacted with multiple CID&lt;BR /&gt;&lt;BR /&gt;JID is a job ID&lt;BR /&gt;CID is a customer ID&lt;BR /&gt;&lt;BR /&gt;I want to know where the same job interacted with more than one customer, and would like to output it in a MV field.&amp;nbsp; I achieve roughly what I want with this:&lt;BR /&gt;&lt;BR /&gt;index="index-34" host="jobserver12-*" "Concurrent:" cmd="invite"&lt;BR /&gt;| eval _raw=log | rex (cid:\s(?&amp;lt;cid&amp;gt;\d+)\s) | rex (jid:\s(?&amp;lt;jid&amp;gt;\d+)\s)&lt;BR /&gt;| stats count values(cid) by jid&lt;BR /&gt;&lt;BR /&gt;But I want to know how to do this directly, I tried with mvcombine but it looks like the fields have to have the exact same values.&amp;nbsp; Both JID and CID vary.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:25:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522065#M147196</guid>
      <dc:creator>jonzatlmi</dc:creator>
      <dc:date>2020-09-29T17:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: make multivalue field from job ID matching multiple customer IDs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522078#M147203</link>
      <description>&lt;P&gt;I am not sure why you would think this isn't "doing it directly".&amp;nbsp;&amp;nbsp; Perhaps if you describe what you think that would look like, and why the stats way feels roundabout it would help?&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may be a few tweaks to make it better, though.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="index-34" host="jobserver12-*" "Concurrent:" cmd="invite"
| rex field=log (cid:\s+(?&amp;lt;cid&amp;gt;\d+)\s) | rex field=log (jid:\s+(?&amp;lt;jid&amp;gt;\d+)\s)
| stats dc(cid) values(cid) by jid&lt;/LI-CODE&gt;&lt;P&gt;Try that one, it&lt;/P&gt;&lt;P&gt;a) uses the `field=` parameter of `rex` instead of changing _raw.&lt;/P&gt;&lt;P&gt;b) also does a `dc(cid)` for a distinct count of the values of cid, per jid.&lt;/P&gt;&lt;P&gt;Happy Splunking!&amp;nbsp; And be sure to let us know if that helps or not.&lt;/P&gt;&lt;P&gt;-Rich&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:16:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522078#M147203</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2020-09-29T18:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: make multivalue field from job ID matching multiple customer IDs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522096#M147207</link>
      <description>&lt;P&gt;To me, it feels like a non-direct way of getting the desired result because I couldn't &lt;STRONG&gt;specifically&lt;/STRONG&gt; say that I want the results of these fields to be combined into a &lt;EM&gt;multivalue &lt;/EM&gt;styleconcatenation.&amp;nbsp; I was hoping to learn something (which I did from your reply, thank you &lt;EM&gt;very&lt;/EM&gt; much) that I could use to understand multivalue fields better.&amp;nbsp; But in the end, these are the exact results I think I'm looking for so I will pick my battles, particular the ones where I succeed I guess.&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:27:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522096#M147207</guid>
      <dc:creator>jonzatlmi</dc:creator>
      <dc:date>2020-09-29T20:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: make multivalue field from job ID matching multiple customer IDs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522123#M147213</link>
      <description>&lt;P&gt;Ah yes, understood.&lt;/P&gt;&lt;P&gt;MV fields are sort of weird little things in Splunk-land.&amp;nbsp; I love 'em, they're really useful, but they sometimes behave in a way common sense would say they shouldn't.&amp;nbsp;&amp;nbsp; On the other hand, I think it's mostly sensible. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So!&amp;nbsp; Maybe a tiny pointer to help with understanding, and maybe how to play with some mv fields.&lt;/P&gt;&lt;P&gt;One thing we find ourselves doing a lot of, in order to create a run-anywhere search for examples here in Answers and in Slack, is something like the following.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval dates="2020-04-18:2 2020-04-24:5 2020-05-02:9 2020-05-09:7 2020-05-16:11 2020-05-23:8 2020-05-30:11 2020-06-06:9 2020-06-13:14" 
| makemv delim=" " dates 
| mvexpand dates 
| makemv delim=":" dates 
| eval date=mvindex(dates,0), count=mvindex(dates,1) 
| eval _time = strptime(date, "%Y-%m-%d") &lt;/LI-CODE&gt;&lt;P&gt;The explanation may give you a kick start here.&lt;/P&gt;&lt;P&gt;Do note, you can - and I recommend! - running this by starting with the first line, then add the second and run it again, and so on.&amp;nbsp; That way you can see each line and what it does to the previous results.&lt;/P&gt;&lt;P&gt;makeresults generates an empty event.&lt;/P&gt;&lt;P&gt;The eval just creates a simple field called "dates" with that big string in it.&lt;/P&gt;&lt;P&gt;We then make the field "dates" into a multi-valued field by splitting it on spaces.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that it's an mv field, we can 'mvexpand' it into separate events so now I have a series of precise dates&amp;nbsp; in the events.&lt;/P&gt;&lt;P&gt;Now comes the fun!&amp;nbsp; Now we make the new split-up field into a mv field by telling it to split it on the colon.&lt;/P&gt;&lt;P&gt;We don't actually want to expand that again, because then we'd have dates and "counts" on separate events.&amp;nbsp; Instead, we use mvindex() to pull out the first mv-value of the mv-field dates and call it 'date', and again pull out a count from the second mv-value of the mv-field.&lt;/P&gt;&lt;P&gt;Then last I set _time to be that date we pulled out.&lt;/P&gt;&lt;P&gt;So, that's just a bit of playing around with MV stuff, thought you might find it fun or at least useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For what it's worth, that search was a run anywhere I created to illustrate the bug that if the Splunk command "predict" is fed data where it has empty "left side" data (e.g. earlier), then it goofs up the graphs.&lt;/P&gt;&lt;P&gt;It's pretty funny and if you trendline some data with smoothing it over 5 periods or something (sma5) before predicting it...&lt;/P&gt;&lt;P&gt;You can see it for yourself.&amp;nbsp; Take the whole search below&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval dates="2020-04-18:2 2020-04-24:5 2020-05-02:9 2020-05-09:7 2020-05-16:11 2020-05-23:8 2020-05-30:11 2020-06-06:9 2020-06-13:14" 
| makemv delim=" " dates 
| mvexpand dates 
| makemv delim=":" dates 
| eval date=mvindex(dates,0), count=mvindex(dates,1) 
| eval _time = strptime(date, "%Y-%m-%d") 
| timechart sum(count) as count span=1w 
| trendline sma5(count) as smooth_count 
| predict smooth_count
| fields - smooth_count count&lt;/LI-CODE&gt;&lt;P&gt;Then change to the Visualization tab, then switch it to a line chart.&amp;nbsp; Follow the prediction line carefully...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Super fun.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:16:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522123#M147213</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2020-09-30T00:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: make multivalue field from job ID matching multiple customer IDs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522812#M147440</link>
      <description>&lt;P&gt;Thank you for that, complex enough to dig into, and straightforward enough to figure out.&lt;BR /&gt;&lt;BR /&gt;Is it right to gleam that MV is mostly a world where you're working with single events, not one where you're combining fields from separate events?&lt;BR /&gt;&lt;BR /&gt;In your example we are being playful with the `dates` field that we created, putting it through MV and splitting it and reassembling it in various ways.&amp;nbsp; But this is a per event result, that's what makes me thing it's not something to go across multiple events.&lt;BR /&gt;&lt;BR /&gt;Thanks again, very much!&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2020 18:58:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522812#M147440</guid>
      <dc:creator>jonzatlmi</dc:creator>
      <dc:date>2020-10-03T18:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: make multivalue field from job ID matching multiple customer IDs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522820#M147443</link>
      <description>&lt;P&gt;Yep, exactly right - multi-value fields are those that are in a single event.&amp;nbsp; By definition, when you have more than one event, ... they're just separate values for the field, not multiple values inside one field content.&lt;/P&gt;&lt;P&gt;Though you really can combine other events together, with a field being made multi-value too.&amp;nbsp; Oh, now I think I've done it and confused it all back up again.&lt;/P&gt;&lt;P&gt;What you are doing is taking events that are otherwise the same,&amp;nbsp; smashing them together on the field that isn't the same, and making that new single event have that one non-same-content field into an mv.&lt;/P&gt;&lt;P&gt;Take a look at this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=2
| streamstats count
| eval name = "Myrtle"
| eval occupation = "Haberdasher"
| eval favorite_foods = if(count=1, "Ice Cream", "Pizza")&lt;/LI-CODE&gt;&lt;P&gt;Myrtle the Haberdasher likes both Ice Cream and Pizza.&amp;nbsp; Two events, one for each, sort of like if you flattened a normalized database by doing a join in your select off the "people" and "favorite_foods" tables.&lt;/P&gt;&lt;P&gt;If you tried to mvcombine favorite foods, you'll find you can't - and the reason IMO is very enlightening.&amp;nbsp; Here's the non-working try:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=2
| streamstats count
| eval name = "Myrtle"
| eval occupation = "Haberdasher"
| eval favorite_foods = if(count=1, "Ice Cream", "Pizza")
| mvcombine delim="," favorite_foods&lt;/LI-CODE&gt;&lt;P&gt;This still leaves you with two events.&lt;/P&gt;&lt;P&gt;An that's because not all the fields are the same yet - you'll see I left the streamstats "count" field in there, so that keeps Splunk from putting those events together because it doesn't know what to do about that "other" different field.&amp;nbsp; "Favorite_foods" it could make into an mv, but count?&amp;nbsp;&lt;/P&gt;&lt;P&gt;(And unfortunately, you can't mvcombine on two fields at once.&amp;nbsp; Argh, I should check for an idea to make this better... OK there wasn't so I made one, feel free to toss a vote or two onto it &lt;A href="https://ideas.splunk.com/ideas/EID-I-595" target="_blank"&gt;https://ideas.splunk.com/ideas/EID-I-595&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;So if you add in a 'fields - count' it'll now work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=2
| streamstats count
| eval name = "Myrtle"
| eval occupation = "Haberdasher"
| eval favorite_foods = if(count=1, "Ice Cream", "Pizza")
| fields - count
| mvcombine delim="," favorite_foods&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll note I made the two events in an entirely different way than the previous example, using streamstats so I could conditionally make favorite_foods be one of two things.&amp;nbsp; I did this so that we had no MV-style stuff *anywhere* above that mvcombine at the bottom. I figured easier to understand if I didn't already have just used a bunch of mv-stuff to have built the events in the first place only to use mv-stuff to smash it back together, which who knows what tomfoolery I may have done in there?&amp;nbsp; Or to prove that, in the words of a famous moose, that there was "nothing up my sleeve"&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Lastly, you can accomplish this as well by using stats.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=2
| streamstats count
| eval name = "Myrtle"
| eval occupation = "Haberdasher"
| eval favorite_foods = if(count=1, "Ice Cream", "Pizza")
| fields - count
| stats values(favorite_foods) as favorite_foods by name, occupation&lt;/LI-CODE&gt;&lt;P&gt;And in fact, with stats you can totally throw away that "count" field by just ignoring it.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=2
| streamstats count
| eval name = "Myrtle"
| eval occupation = "Haberdasher"
| eval favorite_foods = if(count=1, "Ice Cream", "Pizza")
| stats values(favorite_foods) as favorite_foods by name, occupation&lt;/LI-CODE&gt;&lt;P&gt;So, stats has it better in many ways.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the big drawback to stats is that everything you want to include has to be mentioned either in the values() or in the 'by' clause.&lt;/P&gt;&lt;P&gt;Which of course, when you need it, the way to mv more than one field is with stats, because you can do multiples.&amp;nbsp; Or even all, like in this example.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=2
| streamstats count
| eval name = if(count=1, "Myrtle", "Hyacinth")
| eval occupation = if(count=1, "Haberdasher", "Homemaker")
| eval favorite_foods = if(count=1, "Ice Cream", "Pizza")
| stats values(*) as *&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyhow, happy Splunking, and have fun!&lt;/P&gt;&lt;P&gt;-Rich&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2020 20:49:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/make-multivalue-field-from-job-ID-matching-multiple-customer-IDs/m-p/522820#M147443</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2020-10-03T20:49:02Z</dc:date>
    </item>
  </channel>
</rss>

