# Cardinality on Objects

**URL:** <https://discuss.elastic.co/t/cardinality-on-objects/82345>\
**Category:** Elasticsearch\
**Created:** [April 13, 2017, 7:17pm UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345 "2017-04-13T19:17:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [April 13, 2017, 7:17pm UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345/1 "2017-04-13T19:17:37Z")

</div>

How can I do a cardinality aggregation to count objects? I tried below and it does not work when trying to count the number of distinct addresses in my index. However, if I change employee.address.\* to employee.address.city I get the expected results, but just for the city field. Any help would be appreciated. Thanks.

Kevin

```
{
	"size": 0,
			"aggs": {
				"employee_address": {
					"cardinality": {
						"field": "employee.address.*"
					}
				},
				"positions": {
					"cardinality": {
						"field": "position"
					}
				}
			}
}
```

---

<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 14, 2017, 11:04am UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345/2 "2017-04-14T11:04:10Z")

</div>

Could you copy all these values to a single field at index-time and then run the cardinality aggregation on that field?

---

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [April 18, 2017, 7:48pm UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345/3 "2017-04-18T19:48:41Z")

</div>

Thanks for the suggestion. We have a ton of records that are already processed and indexed and we would have to redo all that in order to change the mapping and I am hoping to avoid that. Hopefully someone has a suggestion of how to do this with the mapping as it is. I wonder if objects are not supported by the cardinality aggregation in general? That is, you can't count the number of distinct objects, just their attributes....

---

<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 19, 2017, 1:40pm UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345/4 "2017-04-19T13:40:27Z")

</div>

This is not supported.

---

<div class="post-metadata">

**Author:** ![krmathieu](https://avatars.discourse-cdn.com/v4/letter/k/b5e925/32.png) [@krmathieu](https://discuss.elastic.co/u/krmathieu)\
**Post date:** [April 19, 2017, 4:51pm UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345/5 "2017-04-19T16:51:57Z")

</div>

Roger that.....I will redo the processing/mapping of the data if this becomes a pressing requirement. Thanks.

Kevin

---

<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:** [May 17, 2017, 4:56pm UTC](https://discuss.elastic.co/t/cardinality-on-objects/82345/6 "2017-05-17T16:56:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
