# Different aggregation count for the same value

**URL:** <https://discuss.elastic.co/t/different-aggregation-count-for-the-same-value/324566>\
**Category:** Elasticsearch\
**Created:** [February 2, 2023, 4:47pm UTC](https://discuss.elastic.co/t/different-aggregation-count-for-the-same-value/324566 "2023-02-02T16:47:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbklein](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mbklein/32/108661_2.png) [@mbklein](https://discuss.elastic.co/u/mbklein)\
**Post date:** [February 2, 2023, 4:47pm UTC](https://discuss.elastic.co/t/different-aggregation-count-for-the-same-value/324566/1 "2023-02-02T16:47:22Z")

</div>

I don't understand the results I'm seeing. I am asking for two different aggs in the same query. The first is “show me the doc counts for `subject.label` for these specific values,” and the second is “show me the doc counts for the 5 most common values within `subject.label`.”

```json
POST my_index/search
{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "selected": {
      "terms": {
        "field": "subject.label",
        "include": ["Buddhist art"],
        "order": { "_count": "desc" },
        "size": 5
      }
    },
    "subject": {
      "terms": {
        "field": "subject.label",
        "order": { "_count": "desc" },
        "size": 5
      }
    }
  }
}

```

Here's the result:

```json
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "userFacets" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "Buddhist art",
          "doc_count" : 12
        }
      ]
    },
    "subject" : {
      "doc_count_error_upper_bound" : 11,
      "sum_other_doc_count" : 1005,
      "buckets" : [
        {
          "key" : "Architecture",
          "doc_count" : 88
        },
        {
          "key" : "Painting",
          "doc_count" : 80
        },
        {
          "key" : "Berkeley (Calif.)",
          "doc_count" : 25
        },
        {
          "key" : "Buddhist art",
          "doc_count" : 11
        },
        {
          "key" : "Church architecture",
          "doc_count" : 10
        }
      ]
    }
  }
}

```

How can the value for `Buddhist art` be `12` in the first agg result and `11` in the second? It's a single agg query on a single index. (There are, in fact, 12 docs with a `subject.label` value of “Buddhist art”.)

Any insight on this would help me stop banging my head against my desk.

---

<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:** [March 2, 2023, 4:48pm UTC](https://discuss.elastic.co/t/different-aggregation-count-for-the-same-value/324566/2 "2023-03-02T16:48:06Z")

</div>

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