# Aggs don't return all records

**URL:** <https://discuss.elastic.co/t/aggs-dont-return-all-records/109951>\
**Category:** Elasticsearch\
**Created:** [December 1, 2017, 3:06pm UTC](https://discuss.elastic.co/t/aggs-dont-return-all-records/109951 "2017-12-01T15:06:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Michelsongs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miguel_michelsongs/32/19766_2.png) [@Miguel\_Michelsongs](https://discuss.elastic.co/u/Miguel_Michelsongs)\
**Post date:** [December 1, 2017, 3:06pm UTC](https://discuss.elastic.co/t/aggs-dont-return-all-records/109951/1 "2017-12-01T15:06:05Z")

</div>

Hi , I've a problem with aggregations , the query we've in production in some scenarios don't return all counts.

```auto
query = {size: 0, :query=>{:filtered=>{:filter=>{:bool=>{:must=>[{:term=>{:account_id=>1}}, {:term=>{:user_id=>1}}], :must_not=>{:term=>{:state=>"deleted"}}}}}}, :aggs=>{"label_names"=>{:terms=>{:field=>"label_ids"}}}}

```

it return records but none all of them, I've reindexed the records but the results are innacurate, we are using only one node and ES version 2.3.3

any hints ?

---

<div class="post-metadata">

**Author:** ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)\
**Post date:** [December 8, 2017, 12:13pm UTC](https://discuss.elastic.co/t/aggs-dont-return-all-records/109951/2 "2017-12-08T12:13:03Z")

</div>

Hi Miguel,

In terms aggregation elasticsearch returns by default the top 10 results. You can provide the size parameter to change it:

```
GET/_search
{
  "size": 0, 
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "account_id": {
              "value": "1"
            }
          }
        },
        {
          "term": {
            "user_id": {
              "value": "1"
            }
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "state": {
              "value": "deleted"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "label_names": {
      "terms": {
        "field": "label_ids.keyword",
        "size": 15
      }
    }
  }
}

```

Please be aware that aggregations results can be [approximated](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-approximate-counts).

Hope it helps,  
LG

---

<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:** [January 5, 2018, 12:13pm UTC](https://discuss.elastic.co/t/aggs-dont-return-all-records/109951/3 "2018-01-05T12:13:07Z")

</div>

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