# Returning multiple values on aggregation

**URL:** <https://discuss.elastic.co/t/returning-multiple-values-on-aggregation/21617>\
**Category:** Elasticsearch\
**Created:** [January 13, 2015, 10:24pm UTC](https://discuss.elastic.co/t/returning-multiple-values-on-aggregation/21617 "2015-01-13T22:24:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [January 14, 2015, 1:07pm UTC](https://discuss.elastic.co/t/returning-multiple-values-on-aggregation/21617/2 "2015-01-14T13:07:40Z")

</div>

Would the top\_hits aggregation help you here? It allows you to display the  
top N documents which fall into a particular bucket in the aggregations.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Colin

On Tuesday, 13 January 2015 22:24:18 UTC, makkalot wrote:

> Hi,
> 
> I have an bulk aggregation and want to display a few of the fields not  
> only the key i'm splitting. The query is something like this :
> 
> {  
> "size": 0,  
> "fields" : ["title"],  
> "aggs": {  
> "group\_by\_authors": {  
> "terms": {  
> "script": "doc['author'].value"  
> },  
> "aggs":{  
> "get\_by\_local\_id":{  
> "terms":{  
> "field":"local\_id"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> With the query above i'm able to split the docs according to the authors  
> and then on sub-aggregation i pull the document ids those people are  
> related to.  
> What i need is instead of getting only the ids (local\_id) to get more  
> fields of document. I can use terms + script but again i have one value  
> back. Which is  
> something like :
> 
> {  
> "size": 0,  
> "fields" : ["title"],  
> "aggs": {  
> "group\_by\_authors": {  
> "terms": {  
> "script": "doc['authors.name'].value + '|' +  
> doc['authors.email'].value"  
> },  
> "aggs":{  
> "get\_by\_local\_id":{  
> "terms":{  
> "field":"local\_id",  
> "script":"doc['type'].value"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> I can do some magic with script to get more values and then parse it in my  
> code but, it becomes very ugly. On docs it says it is possible to get  
> multiple  
> values back on aggregation. Any examples would be very useful.
> 
> Thanks in advance.

--  
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/ea280fc8-ad63-41e2-bf8a-d1668eec9640%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ea280fc8-ad63-41e2-bf8a-d1668eec9640%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

_[View the full topic](https://discuss.elastic.co/t/returning-multiple-values-on-aggregation/21617)._
