Pie chart aggregating elements of an array field


(Guilherme Maranhao) #1

Hi there,

I have the following situation:

1 - My index mapping contains:

 "my_array": {
         "properties": {
                 "desc": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } },
                 "percent": { "type": "half_float" },
                 "quantity": { "type": "integer" },
                 "code": { "type": "keyword" }
         }
 }

A sample document in my index would look like that:

"my_array": [
{ 
	"code": "a1", "desc": "abc", "quantity": "4", "percent": "7.7"
},
{ 
	"code": "a2", "desc": "abc", "quantity": "6", "percent": "12"
},
{
	"code": "b", "desc": "xyz", "quantity": "12", "percent": "23"
},
{
	"code": "c", "desc": "xyz", "quantity": "11", "percent": "21"
},
{
	"code": "d1", "desc": "cde", "quantity": "5", "percent": "9.6"
},
{
	"code": "d2", "desc": "cde", "quantity": "14", "percent": "26.9"
},
{
	"code": "e", "desc": "xyz", "quantity": "0", "percent": "0"
}

I'm trying to make a pie chart in kibana with 3 slices:
1 - The sum of all my_array.desc='abc' quantity;
2 - The sum of all my.array.desc='xyz' quantity;
3 - The sum of my.array.desc='cde' quantity.

I've made the following setting:

  • The slice size aggregation is: SUM (field: my_array.quantity)

  • The split slice bucket is: Terms (field: my_array.desc.keyword)

I was expecting three slices, each one containing the sum of the respective my_array.quantity values. But it's returning three equal slices, which one having the sum of all the my_array.quantity values. It seems it's not considering the terms aggregation to calculate.

Does anybody know what I'm doing wrong? Does it have to do with my mapping structure?

Thanks


(Guilherme Maranhao) #2

I've got it. I need to map the field :my_array with type: nested.

Thanks


(kulkarni) #3

Thanks for circling back with your solutions.

Cheers
Rashmi