# Aggregating on docvalue\_field from inner\_hits

**URL:** <https://discuss.elastic.co/t/aggregating-on-docvalue-field-from-inner-hits/198300>\
**Category:** Elasticsearch\
**Created:** [September 5, 2019, 5:57pm UTC](https://discuss.elastic.co/t/aggregating-on-docvalue-field-from-inner-hits/198300 "2019-09-05T17:57:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Potts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_potts/32/1047_2.png) [@Jeff\_Potts](https://discuss.elastic.co/u/Jeff_Potts)\
**Post date:** [September 5, 2019, 5:57pm UTC](https://discuss.elastic.co/t/aggregating-on-docvalue-field-from-inner-hits/198300/1 "2019-09-05T17:57:25Z")

</div>

I have a query that includes a nested query with inner\_hits enabled. I am using docvalue\_fields within inner\_hits to expose the value from within the nested object that I want to aggregate on:

```
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "permissions.permissions",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "permissions.permissions.authorityType.keyword": {
                        "value": "GROUP"
                      }
                    }
                  },
                  {
                    "term": {
                      "permissions.permissions.inherited": {
                        "value": false
                      }
                    }
                  }
                ],
                "must_not": [
                  {
                    "wildcard": {
                      "permissions.permissions.authority.keyword": {
                        "value": "GROUP_site_*_Site*"
                      }
                    }
                  }
                ]
              }
            },
            "inner_hits": {
              "_source": false,
              "docvalue_fields": [
                "permissions.permissions.authority.keyword"
              ]
            }
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "siteId": {
              "value": "rm"
            }
          }
        }
      ]
    }
  }
}

```

The query works great. What I need now is a list of the unique values for permissions.permissions.authority.keyword across all my hits. How do I write an aggregation that aggregates on the inner\_hits docvalue field? I've tried nested aggregations and non-nested aggregations but I must not have my paths correct or something because I am not even getting a list of buckets.

---

<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:** [October 3, 2019, 6:11pm UTC](https://discuss.elastic.co/t/aggregating-on-docvalue-field-from-inner-hits/198300/2 "2019-10-03T18:11:51Z")

</div>

Closed on October 3, 2019, 6:11pm UTC

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