# Inconsistencies in value count aggregation

**URL:** <https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308>\
**Category:** Elasticsearch\
**Tags:** aggregations\
**Created:** [March 13, 2024, 1:39pm UTC](https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308 "2024-03-13T13:39:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atefeh](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Atefeh](https://discuss.elastic.co/u/Atefeh)\
**Post date:** [March 13, 2024, 1:39pm UTC](https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308/1 "2024-03-13T13:39:58Z")

</div>

I am using the **Value count** aggregation on a fixed interval, (the shards data doesn't change within this interval). However, I am encountering varying results with each query execution. Is it possible that I am obtaining an approximate count instead of exact counts?

p.s. My data is distributed across multiple nodes and shards.

```auto
{
	"size": 1,
	"timeout": "90s",
	"query": {
		"range": {
			"myfield": {
				"from": 1709584200000,
				"to": 1710133200000,
				"include_lower": true,
				"include_upper": true,
				"boost": 1.0
			}
		}
	},
	"aggregations": {
		"cnt": {
			"value_count": {
				"field": "myfield"
			}
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [March 13, 2024, 1:50pm UTC](https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308/2 "2024-03-13T13:50:34Z")

</div>

I expect that this is an approximate count. That's called out for a `terms` aggregation, see: [Terms Agg doc count error](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#terms-agg-doc-count-error). I'm surprised it's not called out for `value_count` in the docs too. I'll go digging and see if this is a gap in our docs.

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [March 13, 2024, 2:53pm UTC](https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308/3 "2024-03-13T14:53:12Z")

</div>

@Atefeh after talking with the team who maintains the `value_count` agg, it seems my initial assumption was wrong, and it should be an exactly count - NOT approximate. It may be that you've found a bug, or that your cluster is having issues.

Can you share some more info?

- what version of Elasticsearch are you using?
- can you reproduce on another index? If so, can you provide the reproduction steps?
- can you share the full output of your responses that differ, and show that there are not any partial shard failures?
- can you check the Elasticsearch logs during the query and share if there are any errors or warnings?

---

<div class="post-metadata">

**Author:** ![Atefeh](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Atefeh](https://discuss.elastic.co/u/Atefeh)\
**Post date:** [March 16, 2024, 8:10am UTC](https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308/5 "2024-03-16T08:10:56Z")

</div>

Thank you for your attention. I am using Elasticsearch v 7.17.9.  
You are right. There are some shard failures in the query response.

```auto
{
	"type": "circuit_breaking_exception",
	"reason": "[parent] Data too large, data for [indices:data/read/search[phase/query]] would be [35868302350/33.4gb], which is larger than the limit of [35701915648/33.2gb], real usage: [35868301824/33.4gb], new bytes reserved: [526/526b], usages [request=0/0b, fielddata=20312178761/18.9gb, in_flight_requests=1052/1kb, model_inference=0/0b, eql_sequence=0/0b, accounting=469451628/447.7mb]",
	"bytes_wanted": 35868302350,
	"bytes_limit": 35701915648,
	"durability": "PERMANENT"
}

```

I also observed a GC message in the node where the shard failed. (GC did not bring memory usage down, before [35712048256], after [35712106128])

---

<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:** [April 13, 2024, 8:11am UTC](https://discuss.elastic.co/t/inconsistencies-in-value-count-aggregation/355308/6 "2024-04-13T08:11:56Z")

</div>

Closed on April 13, 2024, 8:11am UTC

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