# Aggregation is not working occasionally

**URL:** <https://discuss.elastic.co/t/aggregation-is-not-working-occasionally/316392>\
**Category:** Elasticsearch\
**Created:** [October 12, 2022, 2:01am UTC](https://discuss.elastic.co/t/aggregation-is-not-working-occasionally/316392 "2022-10-12T02:01:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [October 12, 2022, 2:01am UTC](https://discuss.elastic.co/t/aggregation-is-not-working-occasionally/316392/1 "2022-10-12T02:01:15Z")

</div>

Hi,

I'm using Elasticsearch 7.16.2 and posting query by Dev Tools of Kibana 7.16.2.

I got strange results from an aggregation query.

When I repeat completely the same query:

```auto
GET ss-mix2_omp-01_active/_search
{
  "size":0,
  "_source": false, 
  "aggs": {
    "order": {
      "nested": {
        "path": "MESSAGE.ORDER_N"
      },
      "aggs": {
        "givecode": {
          "multi_terms": {
            "terms": [{
              "field": "MESSAGE.ORDER_N.RXE.02_GiveCode.01_Identifier",
              "missing": ""
            },{
              "field": "MESSAGE.ORDER_N.RXE.02_GiveCode.02_Text",
              "missing": ""
            }],
            "size":1
          }
        }
      }
    }
  }
}

```

Sometimes I got results ignoring aggregation query:

```auto
{
  "took" : 422,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : [{"..."}]
  }
}

```

containing **1** hit with overall `_source` field. Root `size` and `_source` parameter also looks not working. The `size` for aggregation looks to be used for global `siez` parameter.

Sometimes I got correct results:

```auto
{
  "took" : 28275,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "order" : {
      "doc_count" : 27801024,
      "givecode" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 27357513,
        "buckets" : [
          {
            "key" : [
              "114191701",
              "バイアスピリン錠１００ｍｇ"
            ],
            "key_as_string" : "114191701|バイアスピリン錠１００ｍｇ",
            "doc_count" : 443511
          }
        ]
      }
    }
  }
}

```

It's really strange that the results are inconsistent. Is this expected behavior or a known bug? Is there anything I should check?

I couldn't reproduce the results with a small test index.

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:** [November 9, 2022, 2:01am UTC](https://discuss.elastic.co/t/aggregation-is-not-working-occasionally/316392/2 "2022-11-09T02:01:54Z")

</div>

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