<?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 How to force the sequence of search-time operations to perform calculated fields AFTER lookups ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470963#M132489</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I try to figure out how to perform fields calculation based on rules coming from a lookup table.&lt;/P&gt;

&lt;P&gt;This is my use case :&lt;BR /&gt;
- I have event data coming in plain text format that are ingested into Splunk in "generic_single_line" format&lt;BR /&gt;
- I have configured props.conf to extract fields using regular expression&lt;BR /&gt;
- I have configured lookup table to enrich the event data (code -&amp;gt; label, etc..)&lt;/P&gt;

&lt;P&gt;Now, there's a field that needs to be populated from values extracted from the source and by applying rule defined in the lookup table. Is it possible ?&lt;/P&gt;

&lt;P&gt;Example, my lookup table looks like this : &lt;/P&gt;

&lt;P&gt;code, type, key_fields&lt;BR /&gt;
001, E, field1&lt;BR /&gt;
002, E, field1 + field2&lt;BR /&gt;
003, R, field1 + field3 + field4&lt;BR /&gt;
...etc&lt;/P&gt;

&lt;P&gt;I need to somehow created an output new field called "unique_key" which is the value or the concatenated values defined in the lookup table based on the code value.&lt;/P&gt;

&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:56:01 GMT</pubDate>
    <dc:creator>dhtran</dc:creator>
    <dc:date>2020-09-30T04:56:01Z</dc:date>
    <item>
      <title>How to force the sequence of search-time operations to perform calculated fields AFTER lookups ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470963#M132489</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I try to figure out how to perform fields calculation based on rules coming from a lookup table.&lt;/P&gt;

&lt;P&gt;This is my use case :&lt;BR /&gt;
- I have event data coming in plain text format that are ingested into Splunk in "generic_single_line" format&lt;BR /&gt;
- I have configured props.conf to extract fields using regular expression&lt;BR /&gt;
- I have configured lookup table to enrich the event data (code -&amp;gt; label, etc..)&lt;/P&gt;

&lt;P&gt;Now, there's a field that needs to be populated from values extracted from the source and by applying rule defined in the lookup table. Is it possible ?&lt;/P&gt;

&lt;P&gt;Example, my lookup table looks like this : &lt;/P&gt;

&lt;P&gt;code, type, key_fields&lt;BR /&gt;
001, E, field1&lt;BR /&gt;
002, E, field1 + field2&lt;BR /&gt;
003, R, field1 + field3 + field4&lt;BR /&gt;
...etc&lt;/P&gt;

&lt;P&gt;I need to somehow created an output new field called "unique_key" which is the value or the concatenated values defined in the lookup table based on the code value.&lt;/P&gt;

&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:56:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470963#M132489</guid>
      <dc:creator>dhtran</dc:creator>
      <dc:date>2020-09-30T04:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to force the sequence of search-time operations to perform calculated fields AFTER lookups ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470964#M132490</link>
      <description>&lt;P&gt;There is no way to change the order of operations exactly the way you asked.  However, there are undoubtedly several ways to create the effect you are looking for.&lt;/P&gt;

&lt;P&gt;1) Are there a limited number of potential fields involved?&lt;BR /&gt;&lt;BR /&gt;
2) Is the order of those fields consistent, when they are used? &lt;/P&gt;

&lt;P&gt;If the answer to the above are both yes, then you could do this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;LOOKUP LAYOUT

code  type usefield1 usefield2 usefield3 usefield4
  001   E     Y        N        N        N
  002   E     Y        Y        N        N    
  003   R     Y        N        Y        Y

your search here
| rename COMMENT as "add the lookup fields that say whether to use each field" 
| lookup mylookup.csv code OUTPUT usefield1 usefield2 usefield3 usefield4

| rename COMMENT as "create an empty field and then append field values from each chosen field" 
| eval newkey= ""
| foreach use* [ | eval newkey = mvappend(newkey,case(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;="Y",&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;))]

| rename COMMENT as "flatten the field and kill any spaces between" 
| mvcombine delim="" newkey

| rename COMMENT as "get rid of unneeded fields" 
| fields - use*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are several other ways you could build it, but that would work pretty well.&lt;/P&gt;

&lt;P&gt;The above code expect that for every field name, the relevant column of the lookup table will be &lt;CODE&gt;use&lt;/CODE&gt; followed by the exact field name.  &lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 20:14:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470964#M132490</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-04-10T20:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to force the sequence of search-time operations to perform calculated fields AFTER lookups ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470965#M132491</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/203121"&gt;@DalJeanis&lt;/a&gt; &lt;/P&gt;

&lt;P&gt;Thank you for your interesting answer, and sorry for my late feedback (it was holiday in France yesterday) &lt;/P&gt;

&lt;P&gt;I realised by reading your solution that even it's really a smart one it doesn't provide the desired result because I wasn't clear in my explanation. &lt;/P&gt;

&lt;P&gt;Allow me to add an example to illustrate what I want to achieve&lt;/P&gt;

&lt;P&gt;Imagine the following event data&lt;BR /&gt;
001EAAABBBCCCXXX&lt;BR /&gt;
002EDDDEEEFFFYYY&lt;BR /&gt;
003RGGGHHHKKKZZZ&lt;/P&gt;

&lt;P&gt;Then, with extracting rules from props.conf I will have output fields of my event like this&lt;BR /&gt;
code = 001,type = E, field1 = AAA, field2 = BBB, field3 = CCC, field 4 = XXX&lt;BR /&gt;
code = 002,type = E, field1 = DDD, field2 = EEE, field3 = FFF, field 4 = YYY&lt;BR /&gt;
code = 003,type = R, field1 = GGG, field2 = HHH, field3 = KKK, field 4 = ZZZ&lt;BR /&gt;
and so on...&lt;/P&gt;

&lt;P&gt;The desired result would be something like this&lt;BR /&gt;
code = 001,type = E, &lt;STRONG&gt;field1&lt;/STRONG&gt; = AAA, field2 = BBB, field3 = CCC, field4 = XXX, unique_key=AAA&lt;BR /&gt;
code = 002,type = E, &lt;STRONG&gt;field1&lt;/STRONG&gt; = DDD, &lt;STRONG&gt;field2&lt;/STRONG&gt; = EEE, field3 = FFF, field4 = YYY, unique_key=DDDEEE&lt;BR /&gt;
code = 003,type = R, &lt;STRONG&gt;field1&lt;/STRONG&gt; = GGG, field2 = HHH, &lt;STRONG&gt;field3&lt;/STRONG&gt; = KKK, &lt;STRONG&gt;field4&lt;/STRONG&gt; = ZZZ, unique_key=GGGKKKZZZ&lt;BR /&gt;
...etc&lt;/P&gt;

&lt;P&gt;This is what I meant by "applying extracting rule defined in the lookup table"&lt;BR /&gt;
code, type, key_fields&lt;BR /&gt;
001, E, field1&lt;BR /&gt;
002, E, field1 + field2&lt;BR /&gt;
003, R, field1 + field3 + field4&lt;/P&gt;

&lt;P&gt;Some additional details if it could help&lt;BR /&gt;
- there is approx. 50 fields in total, but the ones which is potentially needed to form the "unique_key" don't exceed 10 (your first question above)&lt;BR /&gt;
- the order has to be exactly the same as configured in props.conf (or in something else) (your 2nd question)&lt;BR /&gt;
- values from the fields used to created "unique_key" could not be null or blank&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:57:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-force-the-sequence-of-search-time-operations-to-perform/m-p/470965#M132491</guid>
      <dc:creator>dhtran</dc:creator>
      <dc:date>2020-09-30T04:57:02Z</dc:date>
    </item>
  </channel>
</rss>

