Why is doc_count_error_upper_bound negative?

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 :

{
	"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 :

    {
    "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,

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):

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.

1 Like

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