# Looking for a sexy solution for Aggregations

**URL:** <https://discuss.elastic.co/t/looking-for-a-sexy-solution-for-aggregations/20635>\
**Category:** Elasticsearch\
**Created:** [November 7, 2014, 4:04pm UTC](https://discuss.elastic.co/t/looking-for-a-sexy-solution-for-aggregations/20635 "2014-11-07T16:04:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazoompa\_3](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@kazoompa\_3](https://discuss.elastic.co/u/kazoompa_3)\
**Post date:** [November 7, 2014, 4:04pm UTC](https://discuss.elastic.co/t/looking-for-a-sexy-solution-for-aggregations/20635/1 "2014-11-07T16:04:20Z")

</div>

Hi,

Consider the aggregation below:

"Sociodemographic\_economic\_characteristics": {  
"terms": {  
"field": "Sociodemographic\_economic\_characteristics",  
"size": 0,  
"min\_doc\_count": 0,  
"order": {  
"\_term": "asc"  
}  
}  
}

This is the result without any filters:

Enter code here...

- Sociodemographic\_economic\_characteristics: {
  - buckets: [
    - {
      - key: Age
      - doc\_count: 93  
}

    - {
      - key: Education
      - doc\_count: 42  
}

    - {
      - key: Ethnic\_race\_religion
      - doc\_count: 17  
}

    - {
      - key: Family\_hh\_struct
      - doc\_count: 55  
}

    - {
      - key: Income
      - doc\_count: 10  
}

    - {
      - key: Labour\_retirement
      - doc\_count: 150  
}

    - {
      - key: Marital\_status
      - doc\_count: 20  
}

    - {
      - key: Residence
      - doc\_count: 20  
}

    - {
      - key: Sex
      - doc\_count: 7  
}  
]  
}

This is the result with the filter:

- Sociodemographic\_economic\_characteristics: {
  - buckets: [
    - {
      - key: Age
      - doc\_count: 0  
}

    - {
      - key: Education
      - doc\_count: 0  
}

    - {
      - key: Ethnic\_race\_religion
      - doc\_count: 0  
}

    - {
      - key: Family\_hh\_struct
      - doc\_count: 0  
}

    - {
      - key: Income
      - doc\_count: 0  
}

    - {
      - key: Labour\_retirement
      - doc\_count: 150  
}

    - {
      - key: Marital\_status
      - doc\_count: 0  
}

    - {
      - key: Residence
      - doc\_count: 0  
}

    - {
      - key: Sex
      - doc\_count: 0  
}  
]  
}

I would like to find a way to have the two combined ine one query search  
such that the client can show the info in this manner:

Age: 0/93  
Education: 0/42  
Ethnic\_race\_religion: 0/17  
Family\_hh\_struct: 0/55  
Income: 0/10  
Labour\_retirement:150/150  
...

As alternatives, I considered doing a Multiple Search or two independent  
search queries, but is there any way to do this in one go using the  
Elasticsearch goodies (nested aggs, etc)

Thanks,  
Ramin

--  
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/350c0c57-4f4d-41a0-ab37-e5075b2ddccb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/350c0c57-4f4d-41a0-ab37-e5075b2ddccb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 10, 2014, 3:36pm UTC](https://discuss.elastic.co/t/looking-for-a-sexy-solution-for-aggregations/20635/2 "2014-11-10T15:36:09Z")

</div>

The only solution that I can think of is to execute your query with a post  
filter, not a filtered query. In this way, your aggregations by default  
will not be filtered. You can then have two histograms, one with the post  
filter used as an aggregation filter, and the other one left alone.

--  
Ivan

On Fri, Nov 7, 2014 at 11:04 AM, kazoompa [rhaeri@p3g.org](mailto:rhaeri@p3g.org) wrote:

> Hi,
> 
> Consider the aggregation below:
> 
> "Sociodemographic\_economic\_characteristics": {  
> "terms": {  
> "field": "Sociodemographic\_economic\_characteristics",  
> "size": 0,  
> "min\_doc\_count": 0,  
> "order": {  
> "\_term": "asc"  
> }  
> }  
> }
> 
> This is the result without any filters:
> 
> Enter code here...
> 
> - Sociodemographic\_economic\_characteristics: {
> - buckets: [
> - {
> - key: Age
> - doc\_count: 93  
> }
> 
> - {
> - key: Education
> - doc\_count: 42  
> }
> 
> - {
> - key: Ethnic\_race\_religion
> - doc\_count: 17  
> }
> 
> - {
> - key: Family\_hh\_struct
> - doc\_count: 55  
> }
> 
> - {
> - key: Income
> - doc\_count: 10  
> }
> 
> - {
> - key: Labour\_retirement
> - doc\_count: 150  
> }
> 
> - {
> - key: Marital\_status
> - doc\_count: 20  
> }
> 
> - {
> - key: Residence
> - doc\_count: 20  
> }
> 
> - {
> - key: Sex
> - doc\_count: 7  
> }  
> ]  
> }
> 
> This is the result with the filter:
> 
> - Sociodemographic\_economic\_characteristics: {
> - buckets: [
> - {
> - key: Age
> - doc\_count: 0  
> }
> 
> - {
> - key: Education
> - doc\_count: 0  
> }
> 
> - {
> - key: Ethnic\_race\_religion
> - doc\_count: 0  
> }
> 
> - {
> - key: Family\_hh\_struct
> - doc\_count: 0  
> }
> 
> - {
> - key: Income
> - doc\_count: 0  
> }
> 
> - {
> - key: Labour\_retirement
> - doc\_count: 150  
> }
> 
> - {
> - key: Marital\_status
> - doc\_count: 0  
> }
> 
> - {
> - key: Residence
> - doc\_count: 0  
> }
> 
> - {
> - key: Sex
> - doc\_count: 0  
> }  
> ]  
> }
> 
> I would like to find a way to have the two combined ine one query search  
> such that the client can show the info in this manner:
> 
> Age: 0/93  
> Education: 0/42  
> Ethnic\_race\_religion: 0/17  
> Family\_hh\_struct: 0/55  
> Income: 0/10  
> Labour\_retirement:150/150  
> ...
> 
> As alternatives, I considered doing a Multiple Search or two independent  
> search queries, but is there any way to do this in one go using the  
> Elasticsearch goodies (nested aggs, etc)
> 
> Thanks,  
> Ramin
> 
> --  
> 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/350c0c57-4f4d-41a0-ab37-e5075b2ddccb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/350c0c57-4f4d-41a0-ab37-e5075b2ddccb%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/350c0c57-4f4d-41a0-ab37-e5075b2ddccb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/350c0c57-4f4d-41a0-ab37-e5075b2ddccb%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/CALY%3DcQBKAF\_COLnA8wR4m-Hnc4AMH%2BojkGy6sVan-CPU8PwnVQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBKAF_COLnA8wR4m-Hnc4AMH%2BojkGy6sVan-CPU8PwnVQ%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:51am UTC](https://discuss.elastic.co/t/looking-for-a-sexy-solution-for-aggregations/20635/3 "2017-07-06T00:51:07Z")

</div>


