# Cardinality not giving expected results

**URL:** <https://discuss.elastic.co/t/cardinality-not-giving-expected-results/17012>\
**Category:** Elasticsearch\
**Created:** [April 15, 2014, 2:39am UTC](https://discuss.elastic.co/t/cardinality-not-giving-expected-results/17012 "2014-04-15T02:39:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Uckun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_uckun/32/1256_2.png) [@Tim\_Uckun](https://discuss.elastic.co/u/Tim_Uckun)\
**Post date:** [April 15, 2014, 2:39am UTC](https://discuss.elastic.co/t/cardinality-not-giving-expected-results/17012/1 "2014-04-15T02:39:44Z")

</div>

I have roughly 50 million records in ES. The data was generated  
artificially and is mostly duplicates. I am executing the following query

{  
size: 0,  
aggregations: {  
by\_month: {

```
        date_histogram: {
            field: "time_stamp",
            interval: "1M",
            format: "yyyy-MM-dd HH:mm"

        },
        aggregations: {
            by_node_mac: {
                terms: {
                    field: "node_mac"
                },
                aggregations: {
                    cardinality: {field: 'device_mac'}
                }

            }
        }
    }
}

```

}

I expect the cardinality of these to be in the hundreds but I am getting  
hundreds of thousands an even millions as a count.

It looks like it's not counting the cardinality but actually counting the  
number of records.

--  
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/68eaee35-1069-4b25-99d4-7719df7d13f6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68eaee35-1069-4b25-99d4-7719df7d13f6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 15, 2014, 10:46am UTC](https://discuss.elastic.co/t/cardinality-not-giving-expected-results/17012/2 "2014-04-15T10:46:08Z")

</div>

Thank you for this report, this indeed looks like a bug. Do you have the  
same issue if you use the cardinality aggregation as a top-level  
aggregation (the way it is executed is a bit different in that case so I am  
thinking the bug might only happen when used as a sub aggregation).

On Tue, Apr 15, 2014 at 4:39 AM, Tim Uckun [timuckun@gmail.com](mailto:timuckun@gmail.com) wrote:

> I have roughly 50 million records in ES. The data was generated  
> artificially and is mostly duplicates. I am executing the following query
> 
> {  
> size: 0,  
> aggregations: {  
> by\_month: {
> 
> ```
> date_histogram: {
> field: "time_stamp",
> interval: "1M",
> format: "yyyy-MM-dd HH:mm"
> 
> },
> aggregations: {
> by_node_mac: {
> terms: {
> field: "node_mac"
> },
> aggregations: {
> cardinality: {field: 'device_mac'}
> }
> 
> }
> }
> }
> }
> 
> ```
> 
> }
> 
> I expect the cardinality of these to be in the hundreds but I am getting  
> hundreds of thousands an even millions as a count.
> 
> It looks like it's not counting the cardinality but actually counting the  
> number of records.
> 
> --  
> 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/68eaee35-1069-4b25-99d4-7719df7d13f6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/68eaee35-1069-4b25-99d4-7719df7d13f6%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/68eaee35-1069-4b25-99d4-7719df7d13f6%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/68eaee35-1069-4b25-99d4-7719df7d13f6%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j5imRf1eCWRcLGpy3dYXrA5n0t%2BYWFFQ1TBV4H8Fgbqjg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5imRf1eCWRcLGpy3dYXrA5n0t%2BYWFFQ1TBV4H8Fgbqjg%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:35am UTC](https://discuss.elastic.co/t/cardinality-not-giving-expected-results/17012/3 "2017-07-06T01:35:48Z")

</div>


