# Aggregations across multiple indices

**URL:** <https://discuss.elastic.co/t/aggregations-across-multiple-indices/22636>\
**Category:** Elasticsearch\
**Created:** [March 12, 2015, 4:04pm UTC](https://discuss.elastic.co/t/aggregations-across-multiple-indices/22636 "2015-03-12T16:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Rohling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_rohling/32/709_2.png) [@Christian\_Rohling](https://discuss.elastic.co/u/Christian_Rohling)\
**Post date:** [March 12, 2015, 4:04pm UTC](https://discuss.elastic.co/t/aggregations-across-multiple-indices/22636/1 "2015-03-12T16:04:11Z")

</div>

Hello Everyone,  
I am attempting to use aggregations to count the number of documents  
matching a given query across multiple indices. What I would like to do, is  
make those counts on distinct keys. Say I had following document in 2  
different indices, aliased together.

````auto
{
    _index: myindex
    _type: mytype
    _id: 1
    _version: 1
    _score: 1
    _source: {
        country: MEXICO
    }
}```

When I make an aggs term query on the field "country" I would like it to
only return a single count for the document with id=1(which exists in both
indices). The actual use case is a bit more complicated than what's
described above, this is just an example of the functionality that I am
looking for. I cannot find any info in the docs, and have asked in the IRC
channel to no avail.

-Christian Rohling

-- 
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALsYvrzV-PyUNUHcUHWNCDBQKz5jV9%3DTPoQ2hW1me8q%2BhBgKDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
````

---

<div class="post-metadata">

**Author:** ![Karl\_Putland](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karl_putland/32/719_2.png) [@Karl\_Putland](https://discuss.elastic.co/u/Karl_Putland)\
**Post date:** [March 12, 2015, 9:34pm UTC](https://discuss.elastic.co/t/aggregations-across-multiple-indices/22636/2 "2015-03-12T21:34:42Z")

</div>

you might look at

> **[Cardinality aggregation | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html#search-aggregations-metrics-cardinality-aggregation)**

--K

Karl Putland  
Senior Engineer  
_SimpleSignal_  
Anywhere: 303-242-8608  
[http://www.simplesignal.com/explainer\_video.php](http://www.simplesignal.com/explainer_video.php)

On Thu, Mar 12, 2015 at 10:04 AM, Christian Rohling [crohling88@gmail.com](mailto:crohling88@gmail.com)  
wrote:

> Hello Everyone,  
> I am attempting to use aggregations to count the number of documents  
> matching a given query across multiple indices. What I would like to do, is  
> make those counts on distinct keys. Say I had following document in 2  
> different indices, aliased together.
> 
> ````auto
> {
> _index: myindex
> _type: mytype
> _id: 1
> _version: 1
> _score: 1
> _source: {
> country: MEXICO
> }
> }```
> 
> When I make an aggs term query on the field "country" I would like it to
> only return a single count for the document with id=1(which exists in both
> indices). The actual use case is a bit more complicated than what's
> described above, this is just an example of the functionality that I am
> looking for. I cannot find any info in the docs, and have asked in the IRC
> channel to no avail.
> 
> -Christian Rohling
> 
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/CALsYvrzV-PyUNUHcUHWNCDBQKz5jV9%3DTPoQ2hW1me8q%2BhBgKDg%40mail.gmail.com
> <https://groups.google.com/d/msgid/elasticsearch/CALsYvrzV-PyUNUHcUHWNCDBQKz5jV9%3DTPoQ2hW1me8q%2BhBgKDg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit 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/CA%2BEXWszW-B43Mc%2B6LZMxA5x2Hym5EPgNFQ%3DZ0a1da7s2yjEAyw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BEXWszW-B43Mc%2B6LZMxA5x2Hym5EPgNFQ%3DZ0a1da7s2yjEAyw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Christian\_Rohling](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_rohling/32/709_2.png) [@Christian\_Rohling](https://discuss.elastic.co/u/Christian_Rohling)\
**Post date:** [March 15, 2015, 2:11am UTC](https://discuss.elastic.co/t/aggregations-across-multiple-indices/22636/3 "2015-03-15T02:11:40Z")

</div>

Karl, thank you. That does solve the problem.

-Christian  
On Mar 12, 2015 5:35 PM, "Karl Putland" [karl@simplesignal.com](mailto:karl@simplesignal.com) wrote:

> you might look at  
> [Cardinality aggregation | Elasticsearch Guide [8.11] | Elastic](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html#search-aggregations-metrics-cardinality-aggregation)
> 
> --K
> 
> Karl Putland  
> Senior Engineer  
> _SimpleSignal_  
> Anywhere: 303-242-8608  
> [http://www.simplesignal.com/explainer\_video.php](http://www.simplesignal.com/explainer_video.php)
> 
> On Thu, Mar 12, 2015 at 10:04 AM, Christian Rohling [crohling88@gmail.com](mailto:crohling88@gmail.com)  
> wrote:
> 
> > Hello Everyone,  
> > I am attempting to use aggregations to count the number of documents  
> > matching a given query across multiple indices. What I would like to do, is  
> > make those counts on distinct keys. Say I had following document in 2  
> > different indices, aliased together.
> > 
> > ````auto
> > {
> > _index: myindex
> > _type: mytype
> > _id: 1
> > _version: 1
> > _score: 1
> > _source: {
> > country: MEXICO
> > }
> > }```
> > 
> > When I make an aggs term query on the field "country" I would like it to
> > only return a single count for the document with id=1(which exists in both
> > indices). The actual use case is a bit more complicated than what's
> > described above, this is just an example of the functionality that I am
> > looking for. I cannot find any info in the docs, and have asked in the IRC
> > channel to no avail.
> > 
> > -Christian Rohling
> > 
> > --
> > 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.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/elasticsearch/CALsYvrzV-PyUNUHcUHWNCDBQKz5jV9%3DTPoQ2hW1me8q%2BhBgKDg%40mail.gmail.com
> > <https://groups.google.com/d/msgid/elasticsearch/CALsYvrzV-PyUNUHcUHWNCDBQKz5jV9%3DTPoQ2hW1me8q%2BhBgKDg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> > .
> > For more options, visit 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/CA%2BEXWszW-B43Mc%2B6LZMxA5x2Hym5EPgNFQ%3DZ0a1da7s2yjEAyw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BEXWszW-B43Mc%2B6LZMxA5x2Hym5EPgNFQ%3DZ0a1da7s2yjEAyw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CA%2BEXWszW-B43Mc%2B6LZMxA5x2Hym5EPgNFQ%3DZ0a1da7s2yjEAyw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CA%2BEXWszW-B43Mc%2B6LZMxA5x2Hym5EPgNFQ%3DZ0a1da7s2yjEAyw%40mail.gmail.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/CALsYvryw0a%2BdwqhZALgJRZAOPcyK%3DWTgvTErscZo0726oV4ybg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALsYvryw0a%2BdwqhZALgJRZAOPcyK%3DWTgvTErscZo0726oV4ybg%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:26am UTC](https://discuss.elastic.co/t/aggregations-across-multiple-indices/22636/4 "2017-07-06T00:26:42Z")

</div>


