# Performance impact of the "include/exclude" fields of an aggregation

**URL:** <https://discuss.elastic.co/t/performance-impact-of-the-include-exclude-fields-of-an-aggregation/36969>\
**Category:** Elasticsearch\
**Created:** [December 11, 2015, 10:40am UTC](https://discuss.elastic.co/t/performance-impact-of-the-include-exclude-fields-of-an-aggregation/36969 "2015-12-11T10:40:41Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![deviantony](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deviantony/32/4478_2.png) [@deviantony](https://discuss.elastic.co/u/deviantony)\
**Post date:** [December 11, 2015, 12:38pm UTC](https://discuss.elastic.co/t/performance-impact-of-the-include-exclude-fields-of-an-aggregation/36969/4 "2015-12-11T12:38:10Z")

</div>

Using the following entities:

```json
{
  "label": "Galaxy S4",
  "categoryPath": ["Smartphone/Android/5.1"]
}

{
  "label": "Galaxy S6",
  "categoryPath": ["Smartphone/Android/6.0"]
}

{
  "label": "Iphone 6s",
  "categoryPath": ["Smartphone/IOS"]
}

```

And the category tree for this example:

```auto
| /
| / Smartphone
| / Smartphone / Android
| / Smartphone / Android / 5.1
| / Smartphone / Android / 6.0
| / Smartphone / IOS

```

What I would like to do is retrieving the number of product per category level, e.g: how many products are located in the "Smartphone" category? And I expect it to return two buckets for the children categories only (Android and IOS).

I'm currently using the following query to retrieve how many products are located in the "Smartphone" category with:

```json
GET my_index/product/_search
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "term": {
          "categoryPath.tokenized": "/Smartphone"
        }
      }
    }
  },
  "aggs": {
    "category": {
      "terms": {
        "field": "categoryPath.tokenized",
        "size": 0,
        "include": "\/Smartphone\/.*",
        "exclude": "\/Smartphone\/.*\/.*"
      }
    }
  }
}

```

Mapping used:

```json
{
  "settings": {
    "analysis": {
      "analyzer": {
        "path_analyzer": {
          "tokenizer": "path_hierarchy"
        }
      }
    }
  },
  "mappings": {
    "product": {
      "properties": {
        "label": {
          "type": "string",
          "analyzer": "english"
        },
        "categoryPath": {
          "type": "string",
          "index": "not_analyzed",
          "doc_values": true,
          "fields": {
            "tokenized": {
              "type": "string",
              "analyzer": "path_analyzer"
            }
          }
        }
      }
    }
  }
}

```

Based on the topic: [Aggregation on a materialized path](https://discuss.elastic.co/t/aggregation-on-a-materialized-path/36519)

---

_[View the full topic](https://discuss.elastic.co/t/performance-impact-of-the-include-exclude-fields-of-an-aggregation/36969)._
