<?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 do you create a table from the following data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432414#M123559</link>
    <description>&lt;P&gt;Assuming these 3 docs, how can I create a table where I dedupe by account (I want the most recently ingested event) and display fields account, account_id, resources{].instanceId, the Tag value where Key = Name. This seems easy without trying to extract the Name tag value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "account_id": 1,
    "account": "dev",
    "resources": [
        {
            "instanceId": 123,
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Instance1"
                },
                {
                    "Key": "Owner",
                    "Value": "Dave"
                }
            ]
        },
        {
            "instanceId": 456,
            "Tags": [
                {
                    "Key": "CostCentre",
                    "Value": "ABC"
                },
                {
                    "Key": "Name",
                    "Value": "Instance2"
                }
            ]
        }
    ]
}

{
    "account_id": 1,
    "account": "dev",
    "resources": [
        {
            "instanceId": 123,
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Instance1"
                },
                {
                    "Key": "Owner",
                    "Value": "Dave"
                }
            ]
        }
    ]
}

{
    "account_id": 2,
    "account": "test",
    "resources": [
        {
            "instanceId": 789,
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Instance1"
                },
                {
                    "Key": "Owner",
                    "Value": "Bob"
                }
            ]
        }
    ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This was my attempt:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dedup account_id  | rename resources{}.Tags{}.Value AS value, resources{}.Tags{}.Key AS key, resources{}.InstanceId AS id | eval x=mvzip(key, value) | mvexpand x | eval x=split(x,",") | eval key=mvindex(x,0) | search key=Name | eval value=mvindex(x,1) | table account account_id id key value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It almost gives me the correct data, but I get each instance per account duplicated in the row for each Name tag. &lt;/P&gt;

&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 10 Dec 2018 08:50:36 GMT</pubDate>
    <dc:creator>stevepkr84</dc:creator>
    <dc:date>2018-12-10T08:50:36Z</dc:date>
    <item>
      <title>How do you create a table from the following data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432414#M123559</link>
      <description>&lt;P&gt;Assuming these 3 docs, how can I create a table where I dedupe by account (I want the most recently ingested event) and display fields account, account_id, resources{].instanceId, the Tag value where Key = Name. This seems easy without trying to extract the Name tag value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "account_id": 1,
    "account": "dev",
    "resources": [
        {
            "instanceId": 123,
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Instance1"
                },
                {
                    "Key": "Owner",
                    "Value": "Dave"
                }
            ]
        },
        {
            "instanceId": 456,
            "Tags": [
                {
                    "Key": "CostCentre",
                    "Value": "ABC"
                },
                {
                    "Key": "Name",
                    "Value": "Instance2"
                }
            ]
        }
    ]
}

{
    "account_id": 1,
    "account": "dev",
    "resources": [
        {
            "instanceId": 123,
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Instance1"
                },
                {
                    "Key": "Owner",
                    "Value": "Dave"
                }
            ]
        }
    ]
}

{
    "account_id": 2,
    "account": "test",
    "resources": [
        {
            "instanceId": 789,
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "Instance1"
                },
                {
                    "Key": "Owner",
                    "Value": "Bob"
                }
            ]
        }
    ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This was my attempt:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dedup account_id  | rename resources{}.Tags{}.Value AS value, resources{}.Tags{}.Key AS key, resources{}.InstanceId AS id | eval x=mvzip(key, value) | mvexpand x | eval x=split(x,",") | eval key=mvindex(x,0) | search key=Name | eval value=mvindex(x,1) | table account account_id id key value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It almost gives me the correct data, but I get each instance per account duplicated in the row for each Name tag. &lt;/P&gt;

&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 08:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432414#M123559</guid>
      <dc:creator>stevepkr84</dc:creator>
      <dc:date>2018-12-10T08:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do you create a table from the following data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432415#M123560</link>
      <description>&lt;P&gt;What do you want your table to look like? &lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:19:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432415#M123560</guid>
      <dc:creator>kmaron</dc:creator>
      <dc:date>2018-12-10T16:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do you create a table from the following data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432416#M123561</link>
      <description>&lt;P&gt;@stevepkr84&lt;/P&gt;

&lt;P&gt;Can you please try below search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | dedup account_id | kv 
| spath path=resources{} output=resources 
| mvexpand resources 
| eval _raw=resources 
| kv 
| rename Tags{}.Key as Tags_Key, Tags{}.Value as Tags_Value 
| eval tmp=mvzip(Tags_Key,Tags_Value) | mvexpand tmp | fields account_id,account tmp instanceId | eval key=mvindex(split(tmp,","),0), value=mvindex(split(tmp,","),1) | rename instanceId as id | table account account_id id key value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{     \"account_id\": 1,     \"account\": \"dev\",     \"resources\": [         {             \"instanceId\": 123,             \"Tags\": [                 {                     \"Key\": \"Name\",                     \"Value\": \"Instance1\"                 },                 {                     \"Key\": \"Owner\",                     \"Value\": \"Dave\"                 }             ]         },         {             \"instanceId\": 456,             \"Tags\": [                 {                     \"Key\": \"CostCentre\",                     \"Value\": \"ABC\"                 },                 {                     \"Key\": \"Name\",                     \"Value\": \"Instance2\"                 }             ]         }     ] } " 
| kv 
| spath path=resources{} output=resources 
| mvexpand resources 
| eval _raw=resources 
| kv 
| rename Tags{}.Key as Tags_Key, Tags{}.Value as Tags_Value 
| eval tmp=mvzip(Tags_Key,Tags_Value) | mvexpand tmp | fields account_id,account tmp instanceId | eval key=mvindex(split(tmp,","),0), value=mvindex(split(tmp,","),1) | rename instanceId as id | table account account_id id key value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:26:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432416#M123561</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-12-10T16:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do you create a table from the following data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432417#M123562</link>
      <description>&lt;P&gt;This looks about right, thank you. The only minor issue is that account_id and account display twice per row.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:41:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432417#M123562</guid>
      <dc:creator>stevepkr84</dc:creator>
      <dc:date>2018-12-10T16:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do you create a table from the following data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432418#M123563</link>
      <description>&lt;P&gt;Yes, bcoz there are multiple key-value pairs with single instanceId. How do you want to display data?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 18:22:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432418#M123563</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-12-10T18:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do you create a table from the following data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432419#M123564</link>
      <description>&lt;P&gt;Exactly as it comes out with your query, but ideally without the duplicated account_id and account showing on each row. But this is good enough for sure so will access the answer, thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 08:37:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-create-a-table-from-the-following-data/m-p/432419#M123564</guid>
      <dc:creator>stevepkr84</dc:creator>
      <dc:date>2018-12-11T08:37:37Z</dc:date>
    </item>
  </channel>
</rss>

