Different aggregation count for the same value

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.”

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:

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

1 Like

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