title: Elasticsearch - using the path hierarchy tokenizer to access different level of categories
body: <p>I'm very new in Elasticsearch and have a question about the hierarchical tokenizer of a path. Here is my code example:</p>
  
  <p>My mapping code:</p>
  
  <pre><code>PUT /my_index
  {
    "settings": {
      "analysis": {
        "analyzer": {
          "path-analyzer": {
            "type": "custom",
            "tokenizer": "path-tokenizer"
          }
        },
        "tokenizer": {
          "path-tokenizer": {
            "type": "path_hierarchy",
            "delimiter": "."
          }
        }
      }
    },
    "mappings": {
      "my_type": {
        "dynamic": "strict",
        "properties": {
          "group_path": {
            "type": "string",
            "index_analyzer": "path-analyzer",
            "search_analyzer": "keyword"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>This is my PUT:</p>
  
  <pre><code>PUT /my_index/my_type/1
  {
    "group_path": ["Book.Thriller.Adult","DVD.Comedy.Kids"]
  }
  </code></pre>
  
  <p>This is my Query:</p>
  
  <pre><code>GET /my_index/my_type/_search?search_type=count
  {
     "aggs": {
        "category": {
           "terms": {
              "field": "group_path",
              "size": 0
           }
        }
     }
  }
  </code></pre>
  
  <p>And the result:</p>
  
  <pre><code>{
     ...
     "aggregations": {
        "category": {
           "buckets": [
              {
                 "key": "Book",
                 "doc_count": 1
              },
              {
                 "key": "Book.Thriller",
                 "doc_count": 1
              },
              {
                 "key": "Book.Thriller.Adult",
                 "doc_count": 1
              },
              {
                 "key": "DVD",
                 "doc_count": 1
              },
              {
                 "key": "DVD.Comedy",
                 "doc_count": 1
              },
              {
                 "key": "DVD.Comedy.Kids",
                 "doc_count": 1
              }
           ]
        }
     }
  }
  </code></pre>
  
  <p>So far is everything good. What I'm looking for is that how can I create buckets for example only for the first category. How can I get result like that:</p>
  
  <pre><code>{
     ...
     "aggregations": {
        "category": {
           "buckets": [
              {
                 "key": "Book",
                 "doc_count": 1
              },
              {
                 "key": "DVD",
                 "doc_count": 1
              }
           ]
        }
     }
  }
  </code></pre>
  
  <p>Thank you for any help.</p>