# Extended stats aggregation on array

**URL:** <https://discuss.elastic.co/t/extended-stats-aggregation-on-array/19313>\
**Category:** Elasticsearch\
**Created:** [August 17, 2014, 11:12pm UTC](https://discuss.elastic.co/t/extended-stats-aggregation-on-array/19313 "2014-08-17T23:12:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuheng](https://avatars.discourse-cdn.com/v4/letter/y/b5ac83/32.png) [@yuheng](https://discuss.elastic.co/u/yuheng)\
**Post date:** [August 17, 2014, 11:12pm UTC](https://discuss.elastic.co/t/extended-stats-aggregation-on-array/19313/1 "2014-08-17T23:12:58Z")

</div>

Hi,

I have a field called 'readings' in my logstash messages which is an array  
consists of 10 float point numbers.

I want to calculate the stats for each individual slots in those arrays.  
For example if I have three readings :

[0,0,0, 1935.25,0,0,0,0,-1235.5, 0]  
[0,0,0, 1936.25,0,0,0,0,-1236.5, 0]  
[0,0,0, 1937.25,0,0,0,0,-1237.5, 0]

and I want the average to show me the average in each slot, which should be:  
[0,0,0, 1936.25,0,0,0,0,-1236.5, 0]

If I do:

....  
aggs =\> {  
reading\_avg =\> {  
avg =\> {  
field =\> "readings"  
}  
}  
},  
.....

Then ES will give me the average of all the 30 elements in this three  
arrays and the average results in one number: 1930.54....

Does anyone has any suggestions how can I do this?

Thanks.

Yuheng

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9c665ba1-5e58-4a4d-a79a-b6acf1aef739%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9c665ba1-5e58-4a4d-a79a-b6acf1aef739%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 18, 2014, 4:32am UTC](https://discuss.elastic.co/t/extended-stats-aggregation-on-array/19313/2 "2014-08-18T04:32:21Z")

</div>

Hello Yuheng ,

I feel there are 2 approach.

1. Instead of storing the elements in an array , store it as 10 fields  
as in element\_1 , element\_2 and so on. And then do a stat aggregation on  
each field.
2. Try using the script facility here -  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html)  
to retrieve the Nth element. Run stat script over it.

Thanks  
Vineeth

On Mon, Aug 18, 2014 at 4:42 AM, Yuheng Du [yuheng.du.hust@gmail.com](mailto:yuheng.du.hust@gmail.com) wrote:

> Hi,
> 
> I have a field called 'readings' in my logstash messages which is an array  
> consists of 10 float point numbers.
> 
> I want to calculate the stats for each individual slots in those arrays.  
> For example if I have three readings :
> 
> [0,0,0, 1935.25,0,0,0,0,-1235.5, 0]  
> [0,0,0, 1936.25,0,0,0,0,-1236.5, 0]  
> [0,0,0, 1937.25,0,0,0,0,-1237.5, 0]
> 
> and I want the average to show me the average in each slot, which should  
> be:  
> [0,0,0, 1936.25,0,0,0,0,-1236.5, 0]
> 
> If I do:
> 
> ....  
> aggs =\> {  
> reading\_avg =\> {  
> avg =\> {  
> field =\> "readings"  
> }  
> }  
> },  
> .....
> 
> Then ES will give me the average of all the 30 elements in this three  
> arrays and the average results in one number: 1930.54....
> 
> Does anyone has any suggestions how can I do this?
> 
> Thanks.
> 
> Yuheng
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/9c665ba1-5e58-4a4d-a79a-b6acf1aef739%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9c665ba1-5e58-4a4d-a79a-b6acf1aef739%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/9c665ba1-5e58-4a4d-a79a-b6acf1aef739%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9c665ba1-5e58-4a4d-a79a-b6acf1aef739%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kX%2BvjAunxexsFZ%3D2UO9JUhMX8y75166RQi5Y24ZhKwVg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kX%2BvjAunxexsFZ%3D2UO9JUhMX8y75166RQi5Y24ZhKwVg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:08am UTC](https://discuss.elastic.co/t/extended-stats-aggregation-on-array/19313/3 "2017-07-06T01:08:05Z")

</div>


