# Return aggs as array rather than object

**URL:** <https://discuss.elastic.co/t/return-aggs-as-array-rather-than-object/23246>\
**Category:** Elasticsearch\
**Created:** [April 15, 2015, 5:58am UTC](https://discuss.elastic.co/t/return-aggs-as-array-rather-than-object/23246 "2015-04-15T05:58:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobby\_Richards](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@Bobby\_Richards](https://discuss.elastic.co/u/Bobby_Richards)\
**Post date:** [April 15, 2015, 5:58am UTC](https://discuss.elastic.co/t/return-aggs-as-array-rather-than-object/23246/1 "2015-04-15T05:58:08Z")

</div>

Wanting to display term aggregations using d3js, hover the aggregations are  
dynamic.

It appears that aggs are returned in an object rather than an array...  
for instance if I have to term aggs; agg1 and agg2

the result is {"aggregations":{"term1":data,"term2":data}

that really kills me, as it seems, and would obviously be convenient for me  
to return the aggs in an array. I guess normally you can request the aggs  
by name but I will not be able to know that ahead of time as it will be  
dynamic.

too tired but perhaps there is a way to convert the json to an array or  
have elasticsearch return the aggs as an array?

Thanks,  
Bobby

--  
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/f4900519-1891-4106-a669-38f43743a76c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4900519-1891-4106-a669-38f43743a76c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 15, 2015, 7:07am UTC](https://discuss.elastic.co/t/return-aggs-as-array-rather-than-object/23246/2 "2015-04-15T07:07:00Z")

</div>

Hi Bobby,

There is no such functionality in elasticsearch so this would have to be  
done on client side.

On Wed, Apr 15, 2015 at 7:58 AM, Bobby Richards [bobby.richards@gmail.com](mailto:bobby.richards@gmail.com)  
wrote:

> Wanting to display term aggregations using d3js, hover the aggregations  
> are dynamic.
> 
> It appears that aggs are returned in an object rather than an array...  
> for instance if I have to term aggs; agg1 and agg2
> 
> the result is {"aggregations":{"term1":data,"term2":data}
> 
> that really kills me, as it seems, and would obviously be convenient for  
> me to return the aggs in an array. I guess normally you can request the  
> aggs by name but I will not be able to know that ahead of time as it will  
> be dynamic.
> 
> too tired but perhaps there is a way to convert the json to an array or  
> have elasticsearch return the aggs as an array?
> 
> Thanks,  
> Bobby
> 
> --  
> 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/f4900519-1891-4106-a669-38f43743a76c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4900519-1891-4106-a669-38f43743a76c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/f4900519-1891-4106-a669-38f43743a76c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f4900519-1891-4106-a669-38f43743a76c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien

--  
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/CAO5%3DkAhCtN\_8U25Ogwp6GT7Vv7QQ-hEzCsTOOSHRP781J1kVnw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAO5%3DkAhCtN_8U25Ogwp6GT7Vv7QQ-hEzCsTOOSHRP781J1kVnw%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, 12:19am UTC](https://discuss.elastic.co/t/return-aggs-as-array-rather-than-object/23246/3 "2017-07-06T00:19:42Z")

</div>


