# Elasticsearch - using the path hierarchy tokenizer to access different level of categories

**URL:** https://discuss.elastic.co/t/elasticsearch-using-the-path-hierarchy-tokenizer-to-access-different-level-of-categories/19220
**Category:** Elasticsearch
**Created:** [August 12, 2014, 7:17am UTC](https://discuss.elastic.co/t/elasticsearch-using-the-path-hierarchy-tokenizer-to-access-different-level-of-categories/19220 "2014-08-12T07:17:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)
#### Post date: [August 12, 2014, 7:17am UTC](https://discuss.elastic.co/t/elasticsearch-using-the-path-hierarchy-tokenizer-to-access-different-level-of-categories/19220/1 "2014-08-12T07:17:48Z")

</div>

I'm very new in Elasticsearch and have a question about the hierarchical  
tokenizer of a path. Here is my code example:

My mapping 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"  
}  
}  
}  
}  
}

This is my PUT:

PUT /my\_index/my\_type/1  
{  
"group\_path": ["Book.Thriller.Adult","DVD.Comedy.Kids"]  
}

This is my Query:

GET /my\_index/my\_type/\_search?search\_type=count  
{  
"aggs": {  
"category": {  
"terms": {  
"field": "group\_path",  
"size": 0  
}  
}  
}  
}

And the result:

{  
...  
"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  
}  
]  
}  
}  
}

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?

{  
...  
"aggregations": {  
"category": {  
"buckets": [  
{  
"key": "Book",  
"doc\_count": 1  
},  
{  
"key": "DVD",  
"doc\_count": 1  
}  
]  
}  
}  
}

Thank you for any help.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/454cb83e-c70a-4c31-b85e-06258b117a4d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/454cb83e-c70a-4c31-b85e-06258b117a4d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:09am UTC](https://discuss.elastic.co/t/elasticsearch-using-the-path-hierarchy-tokenizer-to-access-different-level-of-categories/19220/2 "2017-07-06T01:09:21Z")

</div>


