# Facted navigation with totals, drilling down

**URL:** <https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655>\
**Category:** Elasticsearch\
**Created:** [September 7, 2014, 12:57pm UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655 "2014-09-07T12:57:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Gee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_gee/32/1217_2.png) [@Lee\_Gee](https://discuss.elastic.co/u/Lee_Gee)\
**Post date:** [September 7, 2014, 12:57pm UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655/1 "2014-09-07T12:57:40Z")

</div>

I have two 'types' in an index, or two indices of different types (I'd  
prefer the latter but can live with the former).

I'm running an aggregation by type to implement what my UX people refer to  
as faceted search — which makes Googling for ES help quite tricky.

UX would like to filter by type but retain a count for total hits in each  
aggregation bucket — it the total number of each type of record that  
matches the query.

Can this be done in one query?

Failing that, can two queries be supplied/run in parallel?

Thanks  
Lee

--  
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/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%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 7, 2014, 1:21pm UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655/2 "2014-09-07T13:21:22Z")

</div>

Hello Lee ,

For multiple search queries in a single call , you can use \_msearch -

> **[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 7, 2014 at 6:27 PM, Lee Gee [leegee@gmail.com](mailto:leegee@gmail.com) wrote:

> I have two 'types' in an index, or two indices of different types (I'd  
> prefer the latter but can live with the former).
> 
> I'm running an aggregation by type to implement what my UX people refer to  
> as faceted search — which makes Googling for ES help quite tricky.
> 
> UX would like to filter by type but retain a count for total hits in each  
> aggregation bucket — it the total number of each type of record that  
> matches the query.
> 
> Can this be done in one query?
> 
> Failing that, can two queries be supplied/run in parallel?
> 
> Thanks  
> Lee
> 
> --  
> 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/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%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%3DY\_XH7z%2Bx%3D1mx\_O7OPhHJ56gn%3D3sqYndtMbgfe1XsUdQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DY_XH7z%2Bx%3D1mx_O7OPhHJ56gn%3D3sqYndtMbgfe1XsUdQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![mooky](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@mooky](https://discuss.elastic.co/u/mooky)\
**Post date:** [September 8, 2014, 8:58am UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655/3 "2014-09-08T08:58:12Z")

</div>

Not being too sure of the essence of your question let me fire some random  
info at you 🙂

1. If you use a query (rather than filter) then the aggregation will  
reflect the totals for that query. ie the query is global.
2. If you want to do an aggregation that is independent of that query, then  
you have to set its scope to 'global' - (I cant remember the exact syntax  
right now).
3. If you want to apply another filter criteria, use a filter aggregation  
first, then your subaggregations below that (you can nest aggregations)

Sometimes with a faceted search, you want to show the totals of various  
categories based on the search criteria that already exists. You sometimes  
find you also want to show the categories for which there are zero  
applicable documents (possibly because the chosen filter criteria are such  
that they no longer match) - for that you need to do two aggregations - 1  
to get the the totals - plus global one to get all the categories that have  
count zero with the current criteria.

I hope that helps in some way....

On Sunday, 7 September 2014 13:57:40 UTC+1, Lee Gee wrote:

> I have two 'types' in an index, or two indices of different types (I'd  
> prefer the latter but can live with the former).
> 
> I'm running an aggregation by type to implement what my UX people refer to  
> as faceted search — which makes Googling for ES help quite tricky.
> 
> UX would like to filter by type but retain a count for total hits in each  
> aggregation bucket — it the total number of each type of record that  
> matches the query.
> 
> Can this be done in one query?
> 
> Failing that, can two queries be supplied/run in parallel?
> 
> Thanks  
> Lee

--  
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/97fab7ec-c2ef-42cd-8a82-6620d3ed8d4b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/97fab7ec-c2ef-42cd-8a82-6620d3ed8d4b%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 8, 2014, 6:56pm UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655/4 "2014-09-08T18:56:23Z")

</div>

Hello Lee ,

Post filter might be what you are looking for.  
Post filters are only applied once aggregation is done -

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

Hence you can do the terms aggregation on \_type field , and filter using  
post filter.  
It should fit your use case perfectly.

Thanks  
Vineeth

On Sun, Sep 7, 2014 at 6:27 PM, Lee Gee [leegee@gmail.com](mailto:leegee@gmail.com) wrote:

> I have two 'types' in an index, or two indices of different types (I'd  
> prefer the latter but can live with the former).
> 
> I'm running an aggregation by type to implement what my UX people refer to  
> as faceted search — which makes Googling for ES help quite tricky.
> 
> UX would like to filter by type but retain a count for total hits in each  
> aggregation bucket — it the total number of each type of record that  
> matches the query.
> 
> Can this be done in one query?
> 
> Failing that, can two queries be supplied/run in parallel?
> 
> Thanks  
> Lee
> 
> --  
> 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/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/8a815ff7-3fb0-480f-ab4a-0786577d4cb6%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%3D%2B7EM%2BxBcSiLs\_2EqjX%2BHBGiXZbRdAXMk%3DNh\_oA151KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3D%2B7EM%2BxBcSiLs_2EqjX%2BHBGiXZbRdAXMk%3DNh_oA151KA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Lee\_Gee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_gee/32/1217_2.png) [@Lee\_Gee](https://discuss.elastic.co/u/Lee_Gee)\
**Post date:** [September 12, 2014, 7:48am UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655/5 "2014-09-12T07:48:51Z")

</div>

Thank you, all.

On Sunday, September 7, 2014 1:57:40 PM UTC+1, Lee Gee wrote:

> I have two 'types' in an index, or two indices of different types (I'd  
> prefer the latter but can live with the former).
> 
> I'm running an aggregation by type to implement what my UX people refer to  
> as faceted search — which makes Googling for ES help quite tricky.
> 
> UX would like to filter by type but retain a count for total hits in each  
> aggregation bucket — it the total number of each type of record that  
> matches the query.
> 
> Can this be done in one query?
> 
> Failing that, can two queries be supplied/run in parallel?
> 
> Thanks  
> Lee

--  
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/77035121-06ac-436f-8165-9ab44bc1b47c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/77035121-06ac-436f-8165-9ab44bc1b47c%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, 1:02am UTC](https://discuss.elastic.co/t/facted-navigation-with-totals-drilling-down/19655/6 "2017-07-06T01:02:50Z")

</div>


