<?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: Combining Searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741356#M240601</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/308386"&gt;@tchamp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about something like this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath "data.fruit.common.type" output=fruitType 
| eval colorPath="data.fruit." . fruitType . ".color" 
| eval fruitColor=json_extract(_raw,colorPath)&lt;/LI-CODE&gt;&lt;P&gt;Below is a screenshot of how this might work (based on a sample data gen)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="livehybrid_0-1741640442487.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/38073i3C2A43E4F997D07F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="livehybrid_0-1741640442487.png" alt="livehybrid_0-1741640442487.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is the full SPL for the example&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval json="[{\"data\":{\"fruit\":{\"common\":{\"type\":\"apple\",\"foo\":\"bar1\"},\"apple\":{\"color\":\"red\",\"size\":\"medium\",\"smell\":\"sweet\"}}}},{\"data\":{\"fruit\":{\"common\":{\"type\":\"pear\",\"foo\":\"bar2\"},\"pear\":{\"color\":\"green\",\"size\":\"medium\",\"taste\":\"sweet\"}}}}]"
| eval events=json_array_to_mv(json)
| mvexpand events
| eval _raw=events
| fields _raw
| spath "data.fruit.common.type" output=fruitType 
| eval colorPath="data.fruit." . fruitType . ".color" 
| eval fruitColor=json_extract(_raw,colorPath)&lt;/LI-CODE&gt;&lt;P&gt;Please let me know how you get on and consider adding karma to this or any other answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
    <pubDate>Mon, 10 Mar 2025 21:01:05 GMT</pubDate>
    <dc:creator>livehybrid</dc:creator>
    <dc:date>2025-03-10T21:01:05Z</dc:date>
    <item>
      <title>Combining Searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741354#M240600</link>
      <description>&lt;P&gt;I am trying to figure out the best way to perform this search. I have some json log/events where the event data is slightly different based on the type of fruit (this is just an example). I have two searches that return each thing that I want. I'm not sure if it is best to try and combine the two searches or if there is a better way all together.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of my event data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Event Type 1
{
    "data": {
        "fruit": {
            "common": {
                "type": "apple",
                "foo": "bar1"
            },
            "apple": {
                "color": "red",
                "size": "medium",
                "smell": "sweet"
            }
        }
    }
}

Event Type 2
{
    "data": {
        "fruit": {
            "common": {
                "type": "pear",
                "foo": "bar2"
            },
            "pear": {
                "color": "green",
                "size": "medium",
                "taste": "sweet"
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract all of the "color" values from all of the log/json messages. I have two separate queries that extract each one but I want them in a single table.&lt;/P&gt;&lt;P&gt;Here are my current queries/searches:&lt;/P&gt;&lt;P&gt;index=main | spath "data.pear.color" | search "data.pear.color"=* | eval fruitColor='data.pear.color' | table _time, fruitColor&lt;/P&gt;&lt;P&gt;index=main | spath "data.apple.color" | search "data.apple.color"=* | eval fruitColor='data.apple.color' | table _time, fruitColor&lt;/P&gt;&lt;P&gt;I know that there must be a way to do something with the 'type' field to do what I want but can't seem to figure it out.&lt;/P&gt;&lt;P&gt;Any suggestion is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 20:37:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741354#M240600</guid>
      <dc:creator>tchamp</dc:creator>
      <dc:date>2025-03-10T20:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741356#M240601</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/308386"&gt;@tchamp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about something like this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath "data.fruit.common.type" output=fruitType 
| eval colorPath="data.fruit." . fruitType . ".color" 
| eval fruitColor=json_extract(_raw,colorPath)&lt;/LI-CODE&gt;&lt;P&gt;Below is a screenshot of how this might work (based on a sample data gen)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="livehybrid_0-1741640442487.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/38073i3C2A43E4F997D07F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="livehybrid_0-1741640442487.png" alt="livehybrid_0-1741640442487.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is the full SPL for the example&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval json="[{\"data\":{\"fruit\":{\"common\":{\"type\":\"apple\",\"foo\":\"bar1\"},\"apple\":{\"color\":\"red\",\"size\":\"medium\",\"smell\":\"sweet\"}}}},{\"data\":{\"fruit\":{\"common\":{\"type\":\"pear\",\"foo\":\"bar2\"},\"pear\":{\"color\":\"green\",\"size\":\"medium\",\"taste\":\"sweet\"}}}}]"
| eval events=json_array_to_mv(json)
| mvexpand events
| eval _raw=events
| fields _raw
| spath "data.fruit.common.type" output=fruitType 
| eval colorPath="data.fruit." . fruitType . ".color" 
| eval fruitColor=json_extract(_raw,colorPath)&lt;/LI-CODE&gt;&lt;P&gt;Please let me know how you get on and consider adding karma to this or any other answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 21:01:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741356#M240601</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-03-10T21:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741358#M240602</link>
      <description>&lt;P&gt;1. That's awful data. Either make your data normalized (causing a bunch of problems) or make it redundant (causing other problems &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; - here you have both approaches mixed.&lt;/P&gt;&lt;P&gt;2. Don't put data into main index.&lt;/P&gt;&lt;P&gt;3. You can either use coalesce or foreach. A coalesce example:&lt;/P&gt;&lt;PRE&gt;index=main&lt;BR /&gt;| spath&lt;BR /&gt;| search 'data.fruit.common.type' IN ("apple","pear")&lt;BR /&gt;| eval color=coalesce('data.pear.color','data.apple.color')&lt;/PRE&gt;&lt;P&gt;EDIT: Fixed field references in coalesce() - without single quotes Splunk would interpret it as concatenating fields data, pear/apple and color.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 09:23:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741358#M240602</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-03-11T09:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741361#M240603</link>
      <description>&lt;P&gt;This seems really close to working. It does work for the dataset that I provided but isn't working for my actual dataset. I have not figured out why just yet. My actual dataset is MUCH larger and convoluted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As&amp;nbsp;&lt;SPAN&gt;PickleRick pointed out, this is awful data!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 02:49:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741361#M240603</guid>
      <dc:creator>tchamp</dc:creator>
      <dc:date>2025-03-11T02:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741402#M240613</link>
      <description>&lt;P&gt;Using your SPL, I expanded it a bit to be closer to my dataset. This new SPL is not working whereas the one you provided does in deed work. Maybe it is something stupid but I'm stumped!&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval json="[{
  \"data\": {
    \"tree\": {
      \"branch\": {
        \"common\": {
          \"type\": \"Apple\"
        },
        \"apple\": {
          \"color\": \"red\"
        }
      }
    }
  }
}]"
| eval events=json_array_to_mv(json)
| mvexpand events
| eval _raw=events
| fields _raw
| spath "data.tree.branch.common.type" output=TypeTemp
| eval type = lower(TypeTemp)
| eval colorPath="data.tree.branch." . type . ".color "
| eval color=json_extract(_raw,colorPath)
| table _time, color, type, colorPath&lt;/LI-CODE&gt;&lt;P&gt;Suggestions welcome once again.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 13:14:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741402#M240613</guid>
      <dc:creator>tchamp</dc:creator>
      <dc:date>2025-03-11T13:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combining Searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741403#M240614</link>
      <description>&lt;P&gt;I found that I had a typo!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":sleepy_face:"&gt;😪&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 13:33:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-Searches/m-p/741403#M240614</guid>
      <dc:creator>tchamp</dc:creator>
      <dc:date>2025-03-11T13:33:31Z</dc:date>
    </item>
  </channel>
</rss>

