# Aggregations: Possible to return additional fields?

**URL:** <https://discuss.elastic.co/t/aggregations-possible-to-return-additional-fields/19852>\
**Category:** Elasticsearch\
**Created:** [September 17, 2014, 9:33pm UTC](https://discuss.elastic.co/t/aggregations-possible-to-return-additional-fields/19852 "2014-09-17T21:33:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Addison](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@James\_Addison](https://discuss.elastic.co/u/James_Addison)\
**Post date:** [September 17, 2014, 9:33pm UTC](https://discuss.elastic.co/t/aggregations-possible-to-return-additional-fields/19852/1 "2014-09-17T21:33:01Z")

</div>

Is it possible to do a terms aggregation on a 'tags.id' field but also get  
back the associated 'tags.slug' and 'tags.name' fields? Here's how the  
documents are structured:

{  
"id: 42,  
"name": Beer,  
"tags: [{  
"id": 2,  
"name": "Hoppy",  
"slug": "hoppy"  
}, {  
"id": 2,  
"name": "Hoppy",  
"slug": "hoppy"  
}]  
}

Obviously, this is so that I can avoid additional database or elasticsearch  
queries in order to display UI navigation/filtering elements.

--  
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/0ac8182e-5233-4e6e-8939-fe19bb455561%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0ac8182e-5233-4e6e-8939-fe19bb455561%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:** [September 18, 2014, 6:05am UTC](https://discuss.elastic.co/t/aggregations-possible-to-return-additional-fields/19852/2 "2014-09-18T06:05:03Z")

</div>

Hello James ,

You can try the following

1. Make the tags field nested
2. Do a 2 level aggregation with nested/term type aggregation on id  
attribute over name term aggregation. This way you will get all ids and the  
names associated with it.

Thanks  
Vineeth

On Thu, Sep 18, 2014 at 3:03 AM, James Addison [addi00@gmail.com](mailto:addi00@gmail.com) wrote:

> Is it possible to do a terms aggregation on a 'tags.id' field but also  
> get back the associated 'tags.slug' and 'tags.name' fields? Here's how  
> the documents are structured:
> 
> {  
> "id: 42,  
> "name": Beer,  
> "tags: [{  
> "id": 2,  
> "name": "Hoppy",  
> "slug": "hoppy"  
> }, {  
> "id": 2,  
> "name": "Hoppy",  
> "slug": "hoppy"  
> }]  
> }
> 
> Obviously, this is so that I can avoid additional database or  
> elasticsearch queries in order to display UI navigation/filtering elements.
> 
> --  
> 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/0ac8182e-5233-4e6e-8939-fe19bb455561%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0ac8182e-5233-4e6e-8939-fe19bb455561%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0ac8182e-5233-4e6e-8939-fe19bb455561%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0ac8182e-5233-4e6e-8939-fe19bb455561%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/CAGdPd5k%3D8bWs-CT3%3DmxmMNxhtH4a%3DwQ3otcz3TPNb9epVi5\_gg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k%3D8bWs-CT3%3DmxmMNxhtH4a%3DwQ3otcz3TPNb9epVi5_gg%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:01am UTC](https://discuss.elastic.co/t/aggregations-possible-to-return-additional-fields/19852/3 "2017-07-06T01:01:26Z")

</div>


