<?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: Working with dynamic values in rex and multivalue fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440446#M125239</link>
    <description>&lt;P&gt;Apologies, I should have added an example from the start. All done now.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Aug 2019 15:57:42 GMT</pubDate>
    <dc:creator>moystard</dc:creator>
    <dc:date>2019-08-08T15:57:42Z</dc:date>
    <item>
      <title>Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440444#M125237</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I have been banging my head on a problem for the past 24 hours and I am in great need of your help.&lt;/P&gt;

&lt;P&gt;I am processing data coming from surveys; I have a tabular data set that contains three multi value fields:&lt;BR /&gt;
- one multi value field that contains the questions that were shown to the user (example: q1, q2, q3)&lt;BR /&gt;
- one multi value field that contains  the questions that were answered by the user (example: q2, q3)&lt;BR /&gt;
- one multi value field  that contains the duration it took for the respondent to answer those questions in the format: :&lt;/P&gt;

&lt;P&gt;All this data is dynamic (including question references), and I cannot make any assumption on the fields content and names.&lt;/P&gt;

&lt;P&gt;What I am interested in is reconciliating how long it took for a question that was answered to be answered. Ultimately, I want to check that the duration for every answered question is above a certain static threshold (example: 2000ms). &lt;/P&gt;

&lt;P&gt;I am at the stage where, using &lt;CODE&gt;rex&lt;/CODE&gt;, and &lt;CODE&gt;mvfilter&lt;/CODE&gt;, I am able to generate the data below from raw events, and know if a question has been answered, and if it has a duration. Unfortunately, I have not been able to extract the duration and compare it with the threshold because &lt;CODE&gt;rex&lt;/CODE&gt; and &lt;CODE&gt;match&lt;/CODE&gt; in &lt;CODE&gt;mvfilter&lt;/CODE&gt; do not support dynamic values. My idea was indeed to &lt;CODE&gt;mvexpand&lt;/CODE&gt; the shown questions, and then extract for each shown question if it has been answered, and in how long. So far my search looks like this;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;
| rex field=_raw max_match=0 "question_answer_(?[a-zA-Z_]*)\""&lt;BR /&gt;
| rex field=_raw max_match=0 "question_duration_(?[a-zA-Z_]*\":\d*),"&lt;BR /&gt;
| replace "*\"*" with "**" in question_durations&lt;BR /&gt;
| table shown_questions, answered_questions, question_durations, *&lt;BR /&gt;
| mvexpand shown_questions&lt;BR /&gt;
| eval is_answered=if(match(answered_questions, shown_questions), "true", "false")&lt;BR /&gt;
| eval has_duration=if(match(question_durations, shown_questions), "true", "false")&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Here I am a bit lost as it's fairly unclear to me how I can work with dynamic values to extract the question duration either from the multivalue field &lt;CODE&gt;question_durations&lt;/CODE&gt; or from the individual fields &lt;CODE&gt;question_duration&amp;lt;question-code&amp;gt;&lt;/CODE&gt;. I thought originally to use &lt;CODE&gt;mvfilter(match(questions_durations, shown_questions))&lt;/CODE&gt; to extract the line of the question but it does not work due to the dynamic  &lt;CODE&gt;shown_questions&lt;/CODE&gt; parameter. Putting a static value in there works, but unfortunately that's not an option for me.&lt;/P&gt;

&lt;P&gt;Ultimately, my objective is to be able to check if the duration of all questions that have been answered is above a certain threshold.&lt;/P&gt;

&lt;P&gt;Would you have an idea on how I could achieve this?&lt;/P&gt;

&lt;P&gt;Example of data (before the mvexpand):&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Example of Data"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7484iE70513E2AABCD825/image-size/large?v=v2&amp;amp;px=999" role="button" title="Example of Data" alt="Example of Data" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 11:29:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440444#M125237</guid>
      <dc:creator>moystard</dc:creator>
      <dc:date>2019-08-08T11:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440445#M125238</link>
      <description>&lt;P&gt;Could you please post a couple actual events, sanitized, so we can see the format? It would be helpful to then illustrate what kind of analysis you want to do, using a couple of those events as data. This will help connect the dots.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 12:31:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440445#M125238</guid>
      <dc:creator>jpolvino</dc:creator>
      <dc:date>2019-08-08T12:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440446#M125239</link>
      <description>&lt;P&gt;Apologies, I should have added an example from the start. All done now.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 15:57:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440446#M125239</guid>
      <dc:creator>moystard</dc:creator>
      <dc:date>2019-08-08T15:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440447#M125240</link>
      <description>&lt;P&gt;Hi @moystard,&lt;/P&gt;

&lt;P&gt;"Ultimately, my objective is to be able to check if the duration of all questions that have been answered is above a certain threshold." Do you mean per user ? Or the sum total of the durations ?&lt;/P&gt;

&lt;P&gt;This could be easier than what you're trying to achieve as a question with duration means an answered question, isn't that right ?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 07:44:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440447#M125240</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-09T07:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440448#M125241</link>
      <description>&lt;P&gt;Unfortunately not, a question with duration can be skipped and therefore can be excluded.&lt;/P&gt;

&lt;P&gt;I found a solution to my issue using a foreach loop. I start with the duration and check if the question has been answered instead of the other way around.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 10:30:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440448#M125241</guid>
      <dc:creator>moystard</dc:creator>
      <dc:date>2019-08-09T10:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440449#M125242</link>
      <description>&lt;P&gt;Nice that way you have the duration from the start and all you have to do is confirm "is answered" or not.&lt;/P&gt;

&lt;P&gt;You can also drop all the columns in the table above and keep : answered questions and question duration columns. From there you can MV expand both fields and check for a match between the answered questions and the first part of the duration. If there is then you keep the line. That should work pretty fast as well avoiding foreach loops.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 11:42:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440449#M125242</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-08-09T11:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Working with dynamic values in rex and multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440450#M125243</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="is_answered,has_duration,shown_questions,answered_questions,questions_durations
false,false,q1#q2#q4,q1#q2#q4,q1:3478#q2:3046#q4:12691
false,false,,,q1:1890
false,false,q1#q2#q4,q1#q2#q4,q1:2812#q2:3907#q4:4620
false,true,q1,,q1:0
false,false,,,q1:1551
false,false,q1#q3#q4,q1,q1:3488#q3:3399#q4:1791
false,false,q1#q3#q4,q1#q4,q1:8731#q3:1618#q4:8802
false,false,q1#q3#q4,q1#q4,q1:26155#q3:20770#q4:14013"
| multikv forceheader=1
| table is_answered,has_duration,shown_questions,answered_questions,questions_durations
| foreach *
    [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=split(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,"#")]
`comment("Above is before mvexpand")`
`comment("From here, the logic")`
| streamstats count as session 
| eval counter=if(isnull(shown_questions),0,mvrange(0,mvcount(shown_questions))) 
| stats list(*) as * by session counter 
| rename session as _session ,counter as _counter 
| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = mvindex(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,_counter)]
| table is_answered,has_duration,shown_questions,answered_questions,questions_durations
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi, folks.&lt;BR /&gt;
How about it?&lt;BR /&gt;
Is &lt;CODE&gt;mvexpand&lt;/CODE&gt; necessary? &lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 11:22:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Working-with-dynamic-values-in-rex-and-multivalue-fields/m-p/440450#M125243</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-19T11:22:28Z</dc:date>
    </item>
  </channel>
</rss>

