# Nested aggregation empty bucket

**URL:** <https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722>\
**Category:** Elasticsearch\
**Created:** [July 12, 2018, 10:02am UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722 "2018-07-12T10:02:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zajca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zajca/32/26576_2.png) [@zajca](https://discuss.elastic.co/u/zajca)\
**Post date:** [July 12, 2018, 10:02am UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722/1 "2018-07-12T10:02:31Z")

</div>

Hi,  
I have problem with aggregation, which return no bucket.  
(it's more complicated I did drop useless stuff for this example, thats why it's competence inside competence without any other field)

my mapping:

```auto
{
    "mappings": {
      "competence": {
        "properties": {
          "competence": {
            "type": "nested",
            "properties": {
              "type": {
                "type": "nested",
                "properties": {
                  "name": {
                    "type": "keyword"
                  },
                  "value": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        
        }
      }
    }
}

```

typical record looks like this:

```auto
{
  "_source": {
    "competence": {
      "type": {
        "value": 4,
        "name": "TYPE_4"
      }
    }
  }
}

```

but when I run query:

```auto
{
  "size": 0,
  "aggs": {
    "nested_type": {
      "nested": {
        "path": "competence"
      },
      "aggs": {
        "cmp_type": {
          "terms": {
            "field": "type.value"
          }
        }
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

```

but it will return no bucket

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 26254,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "nested_type": {
      "doc_count": 26254,
      "cmp_type": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Johnnycc1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnnycc1/32/26069_2.png) [@Johnnycc1](https://discuss.elastic.co/u/Johnnycc1)\
**Post date:** [July 12, 2018, 10:07am UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722/2 "2018-07-12T10:07:08Z")

</div>

You need the full field path in the final terms aggregation. I.e. competence.type.value

---

<div class="post-metadata">

**Author:** ![zajca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zajca/32/26576_2.png) [@zajca](https://discuss.elastic.co/u/zajca)\
**Post date:** [July 12, 2018, 10:11am UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722/3 "2018-07-12T10:11:56Z")

</div>

I'll get same result with fullpath

```auto
{
  "size": 0,
  "aggs": {
    "nested_type": {
      "nested": {
        "path": "competence"
      },
      "aggs": {
        "cmp_type": {
          "terms": {
            "field": "competence.type.value"
          }
        }
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

```

--\>

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 26254,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "nested_type": {
      "doc_count": 26254,
      "cmp_type": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Johnnycc1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnnycc1/32/26069_2.png) [@Johnnycc1](https://discuss.elastic.co/u/Johnnycc1)\
**Post date:** [July 15, 2018, 9:46pm UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722/4 "2018-07-15T21:46:42Z")

</div>

Sorry - you also need to go down to the required nested path in the initial aggregation. So... competence.type

---

<div class="post-metadata">

**Author:** ![zajca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zajca/32/26576_2.png) [@zajca](https://discuss.elastic.co/u/zajca)\
**Post date:** [July 20, 2018, 7:41pm UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722/5 "2018-07-20T19:41:39Z")

</div>

That works than you

---

<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 17, 2018, 7:41pm UTC](https://discuss.elastic.co/t/nested-aggregation-empty-bucket/139722/6 "2018-08-17T19:41:49Z")

</div>

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