# Terms aggregation bucket for other documents

**URL:** <https://discuss.elastic.co/t/terms-aggregation-bucket-for-other-documents/191258>\
**Category:** Elasticsearch\
**Created:** [July 18, 2019, 5:13pm UTC](https://discuss.elastic.co/t/terms-aggregation-bucket-for-other-documents/191258 "2019-07-18T17:13:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bogdan-srk](https://avatars.discourse-cdn.com/v4/letter/b/e480ec/32.png) [@bogdan-srk](https://discuss.elastic.co/u/bogdan-srk)\
**Post date:** [July 18, 2019, 5:13pm UTC](https://discuss.elastic.co/t/terms-aggregation-bucket-for-other-documents/191258/1 "2019-07-18T17:13:30Z")

</div>

Hi guys  
I use aggregation to collect data from nested field and stuck a little  
ES allows group data by `rectangle.attributes._id`, but is there any way to get some `'other'` bucket to put there documents that were not added to any of groups? I think bucket would be perfect because i need to do further aggregations with 'other' docs.  
Or maybe there's some cool workaround?

Examples of what i have:

Documents with structure like:

```auto
{
...
  rectangle: {
    attributes: [
      {_id: 'some_id', ...}
    ]
}

```

I use query like this for aggregation

```auto
...
"aggs": {
  "attributes": {
    "nested": {
      "path": "rectangle.attributes"
    },
    "aggs": {
      "attributesCount": {
        "cardinality": {
          "field": "rectangle.attributes._id.keyword"
        }
      },
      "entries": {
        "terms": {
          "field": "rectangle.attributes._id.keyword"
        }
      }
    }
  }
}
...

```

And get this result

```auto
...
"buckets" : [
  {
    "key" : "some_parent_id",
    "doc_count" : 27616,
    "attributes" : {
      "doc_count" : 45,
      "entries" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 0,
        "buckets" : [
          {
            "key" : "some_id",
            "doc_count" : 45,
            "attributeOptionsCount" : {
              "value" : 2
            }
          }
        ]
      }
    }
  }
]
...

```

Is there any way to get to `'other'` documents for this query? like:

```auto
...
"buckets" : [
  {
    "key" : "some_parent_id",
    "doc_count" : 1000,
    "attributes" : {
      "doc_count" : 145,
      "entries" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 0,
        "buckets" : [
          {
            "key" : "some_id",
            "doc_count" : 45
          },
          {
            "key" : "other",
            "doc_count" : 100
          }
        ]
      }
    }
  }
]
...

```

---

<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:** [August 15, 2019, 5:13pm UTC](https://discuss.elastic.co/t/terms-aggregation-bucket-for-other-documents/191258/2 "2019-08-15T17:13:31Z")

</div>

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