# Two same aggregation generate different results

**URL:** <https://discuss.elastic.co/t/two-same-aggregation-generate-different-results/49153>\
**Category:** Elasticsearch\
**Created:** [May 4, 2016, 10:33am UTC](https://discuss.elastic.co/t/two-same-aggregation-generate-different-results/49153 "2016-05-04T10:33:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qiangxiao](https://avatars.discourse-cdn.com/v4/letter/q/ee59a6/32.png) [@qiangxiao](https://discuss.elastic.co/u/qiangxiao)\
**Post date:** [May 4, 2016, 10:33am UTC](https://discuss.elastic.co/t/two-same-aggregation-generate-different-results/49153/1 "2016-05-04T10:33:29Z")

</div>

i want to get the cardinallity of a field in an index whose data will not change. i think both dsl mentioned below have the same meaning. However, they generate different results.

`{ "size" : 0, "query" : { "bool" : { "must" : [{ "term" : { "func" : "summarize" } }, { "range" : { "time" : { "from" : 1461513600000, "to" : 1462204800000, "include_lower" : true, "include_upper" : true } } }] } }, "aggregations" : { "useCount" : { "cardinality" : { "field" : "session" } } } }`

{  
"size" : 0,  
"query" : {  
"bool" : {  
"must" : [ {  
"term" : {  
"func" : "summarize"  
}  
}, {  
"range" : {  
"time" : {  
"from" : 1461513600000,  
"to" : 1462204800000,  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
} ]  
}  
},  
"aggregations" : {  
"func" : {  
"terms" : {  
"field" : "func",  
"size" : 1000  
},  
"aggregations" : {  
"useCount" : {  
"cardinality" : {  
"field" : "session"  
}  
}  
}  
}  
}  
}

i think it is similar to next two sql:  
select count(distinct field1) from index where field2='xxx';  
select count(distinct field1) from index where field2='xxx' group by field2;

---

<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 5, 2017, 10:54pm UTC](https://discuss.elastic.co/t/two-same-aggregation-generate-different-results/49153/2 "2017-07-05T22:54:04Z")

</div>


