# Excluding inner\_hits from top\_hits aggregation

**URL:** <https://discuss.elastic.co/t/excluding-inner-hits-from-top-hits-aggregation/187274>\
**Category:** Elasticsearch\
**Created:** [June 25, 2019, 9:05am UTC](https://discuss.elastic.co/t/excluding-inner-hits-from-top-hits-aggregation/187274 "2019-06-25T09:05:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortenbock](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortenbock/32/13062_2.png) [@mortenbock](https://discuss.elastic.co/u/mortenbock)\
**Post date:** [June 25, 2019, 9:05am UTC](https://discuss.elastic.co/t/excluding-inner-hits-from-top-hits-aggregation/187274/1 "2019-06-25T09:05:05Z")

</div>

I have the following query into a product index, where the product has nested variants.

```
{
  "size": 10,
  "_source": {
    "excludes": "variants"
  },
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "query": {
              "bool": {
                "filter": [
                  {
                    "term": {
                      "variants.assortmentIds": {
                        "value": "1"
                      }
                    }
                  }
                ]
              }
            },
            "path": "variants",
            "inner_hits": {
              "name": "variant_hits"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "designer": {
      "terms": {
        "field": "designerName",
        "size": 1000
      },
      "aggs": {
        "facet_value": {
          "top_hits": {
            "size": 1,
            "_source": {
              "includes": [
                "designerName"
              ]
            }
          }
        }
      }
    }
  }
}

```

In order to reduce the amount of data returned by the query, we exclude the "variants" field from the source, and get the matching variants with the "inner\_hits".

The problem now is, that in my "top\_hits" aggregation, I also get the entire "inner\_hits" list. I really just want the "designerName" field from the top hit, and nothing else.

How can I exclude the "inner\_hits" data in my "top\_hits" aggregation?

---

<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:** [July 23, 2019, 9:05am UTC](https://discuss.elastic.co/t/excluding-inner-hits-from-top-hits-aggregation/187274/2 "2019-07-23T09:05:25Z")

</div>

Closed on July 23, 2019, 9:05am UTC

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