<?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: How to write a recursive search to build a tree structure? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255821#M76606</link>
    <description>&lt;P&gt;this is great working one, however it unable to retrieve all the children recursively, ie. when search for  "777" it would bring only 1 level of children but not their children, i.e:&lt;/P&gt;

&lt;P&gt;account,parent&lt;BR /&gt;
555,777&lt;BR /&gt;
789,777&lt;BR /&gt;
777,0&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;missing 321,555&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2016 19:24:58 GMT</pubDate>
    <dc:creator>unchura</dc:creator>
    <dc:date>2016-12-05T19:24:58Z</dc:date>
    <item>
      <title>How to write a recursive search to build a tree structure?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255819#M76604</link>
      <description>&lt;P&gt;I have a csv index imported in Splunk and it represents static pairs "child-account" structure i,e:&lt;/P&gt;

&lt;P&gt;account,parent &lt;BR /&gt;
126,783&lt;BR /&gt;
125,783&lt;BR /&gt;
124,783&lt;BR /&gt;
123,783&lt;BR /&gt;
321,555&lt;BR /&gt;
555,777&lt;BR /&gt;
789,777&lt;BR /&gt;
999,222&lt;BR /&gt;
783,222&lt;BR /&gt;
777,222&lt;BR /&gt;
222,111&lt;BR /&gt;
111,0&lt;/P&gt;

&lt;P&gt;I need to build a search that would bring back specific branch of the tree structure based on the given parent/branch name i.e&lt;/P&gt;

&lt;P&gt;Search for "783" would bring a table result that looks like this:&lt;/P&gt;

&lt;P&gt;account,parent&lt;BR /&gt;
126,783&lt;BR /&gt;
125,783&lt;BR /&gt;
124,783&lt;BR /&gt;
123,783&lt;BR /&gt;
783,0&lt;/P&gt;

&lt;P&gt;or if a search for "777" would bring only children and all below successors, i.e:&lt;/P&gt;

&lt;P&gt;account,parent&lt;BR /&gt;
321,555&lt;BR /&gt;
555,777&lt;BR /&gt;
789,777&lt;BR /&gt;
777,0&lt;/P&gt;

&lt;P&gt;Ideally, I also need a way to search and bring resulting ancestors for any given child i,e:&lt;BR /&gt;
when searching for "777", that would bring:&lt;/P&gt;

&lt;P&gt;account,parent&lt;BR /&gt;
777,222&lt;BR /&gt;
222,111&lt;BR /&gt;
111,0&lt;/P&gt;

&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 17:52:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255819#M76604</guid>
      <dc:creator>unchura</dc:creator>
      <dc:date>2016-12-05T17:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a recursive search to build a tree structure?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255820#M76605</link>
      <description>&lt;P&gt;I am not able to correlate the pattern of all your three examples. Do you want single search to do all three? or they are three different scenarios you want to capture?&lt;/P&gt;

&lt;P&gt;In any case here is the search string for first case of 783 example (I have used my own input lookup csv file similar to what you have provided and searchField is hard-coded as 783 which you can have a input Dashboard form)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputlookup account_tree | eval searchField=783 |where account=searchField OR parent=searchField | eval parent=if(parent==searchField,parent,0) | fields - searchField
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the output:&lt;BR /&gt;
&lt;STRONG&gt;account   parent&lt;BR /&gt;
126 783&lt;BR /&gt;
125 783&lt;BR /&gt;
124 783&lt;BR /&gt;
123 783&lt;BR /&gt;
783 0&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 19:09:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255820#M76605</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2016-12-05T19:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a recursive search to build a tree structure?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255821#M76606</link>
      <description>&lt;P&gt;this is great working one, however it unable to retrieve all the children recursively, ie. when search for  "777" it would bring only 1 level of children but not their children, i.e:&lt;/P&gt;

&lt;P&gt;account,parent&lt;BR /&gt;
555,777&lt;BR /&gt;
789,777&lt;BR /&gt;
777,0&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;missing 321,555&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 19:24:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255821#M76606</guid>
      <dc:creator>unchura</dc:creator>
      <dc:date>2016-12-05T19:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a recursive search to build a tree structure?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255822#M76607</link>
      <description>&lt;P&gt;There may be a way, but I don't think Splunk is really built for this kind of iteration/recursion.  I don't suppose there is a depth limit to this tree, is there?  &lt;/P&gt;

&lt;P&gt;Here's an example that starts to build the whole tree out, but I'm not sure if there's a way (maybe with foreach or map) to actually build it out to completion.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup account_child.csv 
| table parent account 
| join type=left max=0 account 
    [| inputlookup account_child.csv 
    | rename account as account2 
    | rename parent as account] 
| join type=left max=0 account2 
    [| inputlookup account_child.csv 
    | rename account as account3 
    | rename parent as account2] 
| join max=0 type=left account3 
    [| inputlookup account_child.csv 
    | rename account as account4 
    | rename parent as account3]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Dec 2016 01:30:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255822#M76607</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-12-06T01:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a recursive search to build a tree structure?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255823#M76608</link>
      <description>&lt;P&gt;Could you please confirm whether you want single query to do all three or separate queries will work?&lt;/P&gt;

&lt;P&gt;Identifying single child and all parents would be possible as two separate queries if that works for you.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 04:12:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255823#M76608</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2016-12-06T04:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a recursive search to build a tree structure?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255824#M76609</link>
      <description>&lt;P&gt;It worked and exactly what I looking for. There is no depth limit, but at least its predictable value and I do a finite amount of iterations that would cover the task..  Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 15:52:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-recursive-search-to-build-a-tree-structure/m-p/255824#M76609</guid>
      <dc:creator>unchura</dc:creator>
      <dc:date>2016-12-08T15:52:43Z</dc:date>
    </item>
  </channel>
</rss>

