# Wrong doc\_count on Children Aggregation

**URL:** <https://discuss.elastic.co/t/wrong-doc-count-on-children-aggregation/206903>\
**Category:** Elasticsearch\
**Created:** [November 7, 2019, 6:26am UTC](https://discuss.elastic.co/t/wrong-doc-count-on-children-aggregation/206903 "2019-11-07T06:26:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeeeFOX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deeefox/32/49566_2.png) [@DeeeFOX](https://discuss.elastic.co/u/DeeeFOX)\
**Post date:** [November 7, 2019, 6:26am UTC](https://discuss.elastic.co/t/wrong-doc-count-on-children-aggregation/206903/1 "2019-11-07T06:26:47Z")

</div>

request:

```
POST /test_tsdb_alias/_search?routing=ms_nginxgas3_count&track_total_hits=true
{
  "query": {
    "bool": {
      "filter": [
        {
          "has_parent": {
            "parent_type": "t",
            "query": {
              "bool": {
                "filter": [
                  {
                    "term": {
                      "metric": "ms_nginxgas3_count"
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "range": {
            "ts": {
              "gte": "2019-10-30T13:00:00+0800",
              "lte": "2019-10-30T13:30:00+0800"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "ff": {
      "aggs": {
        "to_p": {
          "parent": {
            "type": "p"
          },
          "aggs": {
            "tag": {
              "terms": {
                "field": "tag._type"
              },
              "aggs": {
                "to_c": {
                  "children": {
                    "type": "p"
                  }
                }
              }
            }
          }
        }
      },
      "filters": {
        "filters": {
          "ts": {
            "range": {
              "ts": {
                "gte": "2019-10-30T13:00:00+0800",
                "lte": "2019-10-30T13:30:00+0800"
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}

```

response:

```
{
  "took" : 1048,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 64714,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "ff" : {
      "buckets" : {
        "ts" : {
          "doc_count" : 64714,
          "to_p" : {
            "doc_count" : 1714,
            "tag" : {
              "doc_count_error_upper_bound" : 0,
              "sum_other_doc_count" : 0,
              "buckets" : [
                {
                  "key" : "formal",
                  "doc_count" : 1624,
                  "to_c" : {
                    "doc_count" : 6568272
                  }
                },
                {
                  "key" : "test",
                  "doc_count" : 90,
                  "to_c" : {
                    "doc_count" : 52343
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

```

=\> The filter doesn't correspond to the children aggregation,  
hits = 64714 vs agg doc\_count = 6568272 + 52343.

Why? How to solve it?  
Thanks!

---

<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:** [December 5, 2019, 6:26am UTC](https://discuss.elastic.co/t/wrong-doc-count-on-children-aggregation/206903/2 "2019-12-05T06:26:56Z")

</div>

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