# Aggregate results on specific attribute

**URL:** <https://discuss.elastic.co/t/aggregate-results-on-specific-attribute/19990>\
**Category:** Elasticsearch\
**Created:** [September 28, 2014, 7:47am UTC](https://discuss.elastic.co/t/aggregate-results-on-specific-attribute/19990 "2014-09-28T07:47:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maarten\_Roosendaal](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Maarten\_Roosendaal](https://discuss.elastic.co/u/Maarten_Roosendaal)\
**Post date:** [September 28, 2014, 7:47am UTC](https://discuss.elastic.co/t/aggregate-results-on-specific-attribute/19990/1 "2014-09-28T07:47:05Z")

</div>

Hi,

I'm trying to solve the following use case with elasticsearch: we want to  
provide users with autocomplete functionality but the results of a typed  
term should be aggregated by type of entity in the index, like brand and  
creator.

For example, i have this in the index (name, type, score)  
brand a score 10  
brand aa score 20  
brand aaa score 11  
brand aaaa score 9

creator a score 30  
creator aa score 10  
creator aaa score 9  
creator aaaa score 11

what i want: top 2 highest scoring results per type (brand, creator) for  
search 'starts with a' should be:  
brand  
brand aa  
brand aaa  
creator  
creator a  
creator aaaa

how can you do this in es? Or do i have to use multiple queries (per type)  
and aggregate the result in the application?

Thanks,  
Maarten

--  
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/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%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 28, 2014, 3:48pm UTC](https://discuss.elastic.co/t/aggregate-results-on-specific-attribute/19990/2 "2014-09-28T15:48:14Z")

</div>

Hello Maarten ,

This is a direct use case of aggregations.  
Simpy use term aggregation for both fields -

> **[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.

Thanks  
Vineeth

On Sun, Sep 28, 2014 at 1:17 PM, Maarten Roosendaal \<[mroosendaal14@gmail.com](mailto:mroosendaal14@gmail.com)

> wrote:

> Hi,
> 
> I'm trying to solve the following use case with elasticsearch: we want to  
> provide users with autocomplete functionality but the results of a typed  
> term should be aggregated by type of entity in the index, like brand and  
> creator.
> 
> For example, i have this in the index (name, type, score)  
> brand a score 10  
> brand aa score 20  
> brand aaa score 11  
> brand aaaa score 9
> 
> creator a score 30  
> creator aa score 10  
> creator aaa score 9  
> creator aaaa score 11
> 
> what i want: top 2 highest scoring results per type (brand, creator) for  
> search 'starts with a' should be:  
> brand  
> brand aa  
> brand aaa  
> creator  
> creator a  
> creator aaaa
> 
> how can you do this in es? Or do i have to use multiple queries (per type)  
> and aggregate the result in the application?
> 
> Thanks,  
> Maarten
> 
> --  
> 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/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%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/CAGdPd5%3DyBT1o-vSNScX3Vy0SujbVcG\_b1gjf4eZecW8\_RNdjgA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DyBT1o-vSNScX3Vy0SujbVcG_b1gjf4eZecW8_RNdjgA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Maarten\_Roosendaal](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Maarten\_Roosendaal](https://discuss.elastic.co/u/Maarten_Roosendaal)\
**Post date:** [September 28, 2014, 5:03pm UTC](https://discuss.elastic.co/t/aggregate-results-on-specific-attribute/19990/3 "2014-09-28T17:03:43Z")

</div>

Hi Vineeth,

Thanks for the reply, it was almost what i was looking for but you pointed  
me in the right direction:

> **[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.

Thanks,  
Maarten

Op zondag 28 september 2014 17:48:26 UTC+2 schreef vineeth mohan:

> Hello Maarten ,
> 
> This is a direct use case of aggregations.  
> Simpy use term aggregation for both fields -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html)
> 
> Thanks  
> Vineeth
> 
> On Sun, Sep 28, 2014 at 1:17 PM, Maarten Roosendaal \<[mroose...@gmail.com](mailto:mroose...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I'm trying to solve the following use case with elasticsearch: we want to  
> > provide users with autocomplete functionality but the results of a typed  
> > term should be aggregated by type of entity in the index, like brand and  
> > creator.
> > 
> > For example, i have this in the index (name, type, score)  
> > brand a score 10  
> > brand aa score 20  
> > brand aaa score 11  
> > brand aaaa score 9
> > 
> > creator a score 30  
> > creator aa score 10  
> > creator aaa score 9  
> > creator aaaa score 11
> > 
> > what i want: top 2 highest scoring results per type (brand, creator) for  
> > search 'starts with a' should be:  
> > brand  
> > brand aa  
> > brand aaa  
> > creator  
> > creator a  
> > creator aaaa
> > 
> > how can you do this in es? Or do i have to use multiple queries (per  
> > type) and aggregate the result in the application?
> > 
> > Thanks,  
> > Maarten
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1e3a7a13-3f2c-47db-b2f1-b066441d9765%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/066cc62c-21ee-4ffe-946f-14404e39947a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/066cc62c-21ee-4ffe-946f-14404e39947a%40googlegroups.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:59am UTC](https://discuss.elastic.co/t/aggregate-results-on-specific-attribute/19990/4 "2017-07-06T00:59:31Z")

</div>


