Terms aggregation bucket for other documents

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:

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

I use query like this for aggregation

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

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

...
"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
          }
        ]
      }
    }
  }
]
...

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