# Trying to get stats on object stored inside an array

**URL:** <https://discuss.elastic.co/t/trying-to-get-stats-on-object-stored-inside-an-array/11694>\
**Category:** Elasticsearch\
**Created:** [April 25, 2013, 3:01pm UTC](https://discuss.elastic.co/t/trying-to-get-stats-on-object-stored-inside-an-array/11694 "2013-04-25T15:01:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian\_2](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@Julian\_2](https://discuss.elastic.co/u/Julian_2)\
**Post date:** [April 25, 2013, 3:01pm UTC](https://discuss.elastic.co/t/trying-to-get-stats-on-object-stored-inside-an-array/11694/1 "2013-04-25T15:01:33Z")

</div>

Hi,

I've walk through a lot of thread to resolve my issue but I think that it's  
not possible. Perhaps someone will have an idea :  
I got a mapping including an array of objects (perhaps it's my mistake ?):

{  
name: Header  
detail: [  
{  
count: 621,  
key: key1  
}  
{  
count: 138,  
key: key2  
}  
]  
}

With this mapping :

"detail":  
{  
"dynamic": "true",  
"properties":  
{  
"count":  
{  
"type": "long"  
},  
"key":  
{  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},

I try to get for each key the sum of the of the count field. So  
I've tried a terms\_stats :

```
  "terms_stats": {
    "key_field": "detail.key",
    "value_field": "detail.count",
    "order": "total",
    "size": 0
  }

```

But the result is not what I'm expected. The count, min, max, total is not  
grouped by the key field but is the count of every objects in the array

{  
term: key1  
count: 2  
total\_count: 2  
min: 138  
max: 621  
total: 759  
mean: 379.5  
}  
{  
term: key2  
count: 2  
total\_count: 2  
min: 138  
max: 621  
total: 759  
mean: 379.5  
}

I've also tried the value\_script :

"terms\_stats": {  
"key\_field": "detail.key",  
"value\_script": "doc['detail.count'].value",  
"order": "total",  
"size": 0  
}

But again it's not what I'm trying to get. Here the result :

{  
term: key1  
count: 1  
total\_count: 1  
min: 1  
max: 1  
total: 1  
mean:1  
}  
{  
term: key2  
count: 1  
total\_count: 1  
min: 1  
max: 1  
total: 1  
mean:1  
}

Someone could tell me if I'm completly getting wrong using these mapping or  
if there is an other solution ?  
Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:39am UTC](https://discuss.elastic.co/t/trying-to-get-stats-on-object-stored-inside-an-array/11694/2 "2017-07-06T02:39:36Z")

</div>


