<?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 it possible to create a multivalue field out of fieldnames with a specific pattern in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315768#M94515</link>
    <description>&lt;P&gt;If would be better if you provided some sample events. Based on the details in the question you can try the following &lt;CODE&gt;rex&lt;/CODE&gt; command with &lt;CODE&gt;max_match=0&lt;/CODE&gt;. Following is the run-anywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="productA=20
productB=50
productC=100"
| rex field=_raw "(?&amp;lt;product&amp;gt;product[^=]+)=(?&amp;lt;qty&amp;gt;.*)" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Sep 2017 13:49:35 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-09-01T13:49:35Z</dc:date>
    <item>
      <title>Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315767#M94514</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;is it possible to create a multivalue field out of fieldnames with a specific pattern?&lt;/P&gt;

&lt;P&gt;Let's say we have several &lt;EM&gt;product&lt;/EM&gt; fields in an event:&lt;BR /&gt;
productA=20&lt;BR /&gt;
productB=50&lt;BR /&gt;
productC=100&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;Can we create a multivalue field that includes all fieldnames that start with "product"?&lt;BR /&gt;
mv_field={productA productB productC}&lt;/P&gt;

&lt;P&gt;Cheers&lt;BR /&gt;
Heinz&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 13:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315767#M94514</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-09-01T13:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315768#M94515</link>
      <description>&lt;P&gt;If would be better if you provided some sample events. Based on the details in the question you can try the following &lt;CODE&gt;rex&lt;/CODE&gt; command with &lt;CODE&gt;max_match=0&lt;/CODE&gt;. Following is the run-anywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="productA=20
productB=50
productC=100"
| rex field=_raw "(?&amp;lt;product&amp;gt;product[^=]+)=(?&amp;lt;qty&amp;gt;.*)" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 13:49:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315768#M94515</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-09-01T13:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315769#M94516</link>
      <description>&lt;P&gt;Here is the part of a sample event. Seems to make a difference&lt;/P&gt;

&lt;P&gt;payload: { [-]&lt;BR /&gt;
    consumablesUsed: {  [-] &lt;BR /&gt;
       Consumable_Grenade: 0&lt;BR /&gt;&lt;BR /&gt;
       Consumable_Healthpack: 0 &lt;BR /&gt;
     }  &lt;/P&gt;

&lt;P&gt;So the mv should include every fieldname that starts with &lt;EM&gt;payload.consumablesUsed.Consumable_&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:36:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315769#M94516</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2020-09-29T15:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315770#M94517</link>
      <description>&lt;P&gt;Try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "Consumable_(?&amp;lt;product&amp;gt;[^:]+):\s(?&amp;lt;qty&amp;gt;\d+)" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Sep 2017 14:48:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315770#M94517</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-09-01T14:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315771#M94518</link>
      <description>&lt;P&gt;Since you have mentioned, payload.consumablesUsed.Consumable_, do you already have JSON data parsed and fields extracted?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 14:49:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315771#M94518</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-09-01T14:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315772#M94519</link>
      <description>&lt;P&gt;yes.&lt;BR /&gt;
the example mentioned above does not work on my side&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 14:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315772#M94519</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2017-09-01T14:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315773#M94520</link>
      <description>&lt;P&gt;How about the updated rex command with &lt;CODE&gt;Consumable_&lt;/CODE&gt; for pattern matching? I tested with your sample data and it worked for me.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="payload: { 
consumablesUsed: { 
Consumable_Grenade: 0 
Consumable_Healthpack: 0 
}"
|  rex field=_raw "Consumable_(?&amp;lt;product&amp;gt;[^:]+):\s(?&amp;lt;qty&amp;gt;\d+)" max_match=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, if you already have JSON fields extracted using KV_MODE, you can try the following in your base search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;YourBaseSearch&amp;gt;
| table payload.consumablesUsed.Consumable_*
| transpose column_name="product"
| rename "row 1" as quantity
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Sep 2017 15:02:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315773#M94520</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-09-01T15:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a multivalue field out of fieldnames with a specific pattern</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315774#M94521</link>
      <description>&lt;P&gt;Assuming that your original fields are &lt;EM&gt;not&lt;/EM&gt; multi-valued fields, then like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_*
| stats count by date_second
| eval date_second = "product" . date_second
| head 5
| eval anchor="X"
| xyseries anchor date_second count

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval mvfield=","
| foreach product* [ eval mvfield = mvfield . $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$ . "," ]
| makemv delim="," mvfield
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Sep 2017 16:19:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-it-possible-to-create-a-multivalue-field-out-of-fieldnames/m-p/315774#M94521</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-02T16:19:33Z</dc:date>
    </item>
  </channel>
</rss>

