# Why is doc\_count\_error\_upper\_bound negative?

**URL:** <https://discuss.elastic.co/t/why-is-doc-count-error-upper-bound-negative/130021>\
**Category:** Elasticsearch\
**Created:** [April 30, 2018, 11:31am UTC](https://discuss.elastic.co/t/why-is-doc-count-error-upper-bound-negative/130021 "2018-04-30T11:31:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunravimv](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@arunravimv](https://discuss.elastic.co/u/arunravimv)\
**Post date:** [April 30, 2018, 11:31am UTC](https://discuss.elastic.co/t/why-is-doc-count-error-upper-bound-negative/130021/1 "2018-04-30T11:31:07Z")

</div>

From the documentation, I was expecting this value to be anything greater than or equal to 0. Please correct me if am wrong and kindly explain (or point to a documentation) when it would be negative.

Attached below is my query and part of the response

Query :

```auto
{
	"from": 0,
	"size": 0,
	"sort": {
		"date.keyword": {
			"order": "asc"
		}
	},
	"aggs": {
		"days": {
			"terms": {
				"field": "dstMongoId.keyword",
				"order": {
					"total_repetitions": "desc"
				},
				"exclude": ["db9566d7-19e3-0877-7edc-9dd1b8203d91"],
				"size": 20,
				"shard_size":40
			},
			"aggs": {
				"total_repetitions": {
					"sum": {
						"field": "repetitions"
					}
				},
				"dsts": {
					"terms": {
						"field": "_index",
						"order": {
							"total_repetitions": "desc"
						},
						"size":15,
						"shard_size":30
					},
					"aggs": {
						"total_repetitions": {
							"sum": {
								"field": "repetitions"
							}
						},
						"postTypes": {
							"terms": {
								"field": "postType.keyword",
								"size":2,
								"shard_size":4
							},
							"aggs": {
								"platforms": {
									"terms": {
										"field": "platform.keyword",
										"size":4,
										"shard_size":8
									},
									"aggs": {
										"total_repetitions": {
											"sum": {
												"field": "repetitions"
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	},
	"query": {
		"bool": {
			"must": [{
					"term": {
						"dstType.keyword": "BRAND"
					}
				},
				{
					"term": {
						"srcType.keyword": "BRAND"
					}
				},
				{
					"term": {
						"srcMongoId.keyword": "db9566d7-19e3-0877-7edc-9dd1b8203d91"
					}
				},
				{
					"range": {
						"date.keyword": {
							"gte": "20170328",
							"lt": "20180329"
						}
					}
				}
			]
		}
	}
}

```

Response :

```auto
    {
    "took": 23,
    "timed_out": false,
    "_shards": {
        "total": 80,
        "successful": 80,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 5248,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "days": {
            "doc_count_error_upper_bound": -1,
            "sum_other_doc_count": 2757,

```

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [April 30, 2018, 4:17pm UTC](https://discuss.elastic.co/t/why-is-doc-count-error-upper-bound-negative/130021/2 "2018-04-30T16:17:29Z")

</div>

If you order by a sub-agg, or doc\_count ascending, the upper bound error will be -1 because we have no way to calculate the upper bound error.

In your agg you have a number of sorts based on the results of a sub-aggregation, which is causing the -1's.

From the docs ([down towards the bottom of this section](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/search-aggregations-bucket-terms-aggregation.html#_per_bucket_document_count_error)):

> These errors can only be calculated in this way when the terms are ordered by descending document count. When the aggregation is ordered by the terms values themselves (either ascending or descending) there is no error in the document count since if a shard does not return a particular term which appears in the results from another shard, it must not have that term in its index. When the aggregation is either sorted by a sub aggregation or in order of ascending document count, the error in the document counts cannot be determined and is given a value of -1 to indicate this.

---

<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 28, 2018, 4:17pm UTC](https://discuss.elastic.co/t/why-is-doc-count-error-upper-bound-negative/130021/3 "2018-05-28T16:17:50Z")

</div>

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