Getting Data In

Grouping by items in an array

Maurice
Explorer

Hi,

I'm hoping someone can help me out here.

I have a property(books) on each event which holds an array of objects.

I would like to group by books{}.name with count on y axis and create a bar chart.

I tried using top books{}.name but this does not seem to give the correct results, seems to miss out on some groups all together

 

{

books:[

        {name: "book1"},

{name: "book2"},

{name: "book3"},

{name: "book3"},

{name: "book1"},

{name: "book1"},

      ]

}

Would you have an idea of how to fix this,

Kind Regards,

Maurice

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Are you extracting the fields with spath first?

| makeresults 
| eval _raw="{
\"books\":[
{\"name\": \"book1\"},
{\"name\": \"book2\"},
{\"name\": \"book3\"},
{\"name\": \"book3\"},
{\"name\": \"book1\"},
{\"name\": \"book1\"},
      ]
}"
| spath
| top books{}.name

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Are you extracting the fields with spath first?

| makeresults 
| eval _raw="{
\"books\":[
{\"name\": \"book1\"},
{\"name\": \"book2\"},
{\"name\": \"book3\"},
{\"name\": \"book3\"},
{\"name\": \"book1\"},
{\"name\": \"book1\"},
      ]
}"
| spath
| top books{}.name

Maurice
Explorer

Thanks a million for the reply.

It really helped focus me in the correct direction.

I ended up having to put an explicit spath before each of my search command that referenced one of the complex object properties.

similar to:

 

 

| spath books{}.name
| search books{}.name
| top books{}.name

 

 
 
Tags (1)
0 Karma
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...