# How to use path\_hierarchy tokenizer

**URL:** https://discuss.elastic.co/t/how-to-use-path-hierarchy-tokenizer/8496
**Category:** Elasticsearch
**Created:** [July 23, 2012, 10:56pm UTC](https://discuss.elastic.co/t/how-to-use-path-hierarchy-tokenizer/8496 "2012-07-23T22:56:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shane](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@shane](https://discuss.elastic.co/u/shane)
#### Post date: [July 23, 2012, 10:56pm UTC](https://discuss.elastic.co/t/how-to-use-path-hierarchy-tokenizer/8496/1 "2012-07-23T22:56:16Z")

</div>

Hello,

I'm setting up our first ElasticSearch server. It's going well so far,  
except I need to figure out how to index our hierarchical categories. I've  
found the path\_tokenizer for that purpose, and I'm attempting to make it  
work. I've been through the docs and other sources, but I'm lost -- there  
seem to be multiple ways to do this.

My understanding is that I should be able to create my index with mappings  
as follows. If it makes any difference, the categories field is an array of  
values.

Am I on the right track? I'm indexing documents but have been unable to  
make any path query work so far.

{  
"index": {},  
"settings": {  
"analysis": {  
"analyzer": {  
"category\_path": {  
"type": "custom",  
"tokenizer": "category\_path"  
}  
},  
"tokenizer": {  
"category\_path": {  
"type": "path\_hierarchy",  
"delimiter": "/"  
}  
}  
}  
},  
"mappings": {  
"Product": {  
"properties": {  
"categories": {  
"type": "string",  
"path": {  
"type": "string",  
"analyzer": "category\_path"  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

### Author: ![kodo65](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kodo65/32/1185_2.png) [@kodo65](https://discuss.elastic.co/u/kodo65)
#### Post date: [August 21, 2012, 1:21pm UTC](https://discuss.elastic.co/t/how-to-use-path-hierarchy-tokenizer/8496/2 "2012-08-21T13:21:25Z")

</div>

Hi Shane!

Have you found a solution to this? I'm also experiencing problems having  
the path\_hierarchy tokenizer to work. I've created a mapping and I've  
issued a number of \_analyze request such as

\_analyze?field=hierarchy&text=level0/level1/level2.../leveln - where  
"hierarchy" is my, well, hierarchy property:)

The result looks exactly the way I want it, creating n-number of terms.  
However when I try to "filter" my resultset based on that property it seems  
like the various terms are not indexed...

If you've found a solution to this I'd be very happy if you would share it  
with me:)

Cheers

On Tuesday, July 24, 2012 12:56:16 AM UTC+2, shane wrote:

> Hello,
> 
> I'm setting up our first Elasticsearch server. It's going well so far,  
> except I need to figure out how to index our hierarchical categories. I've  
> found the path\_tokenizer for that purpose, and I'm attempting to make it  
> work. I've been through the docs and other sources, but I'm lost -- there  
> seem to be multiple ways to do this.
> 
> My understanding is that I should be able to create my index with mappings  
> as follows. If it makes any difference, the categories field is an array of  
> values.
> 
> Am I on the right track? I'm indexing documents but have been unable to  
> make any path query work so far.
> 
> {  
> "index": {},  
> "settings": {  
> "analysis": {  
> "analyzer": {  
> "category\_path": {  
> "type": "custom",  
> "tokenizer": "category\_path"  
> }  
> },  
> "tokenizer": {  
> "category\_path": {  
> "type": "path\_hierarchy",  
> "delimiter": "/"  
> }  
> }  
> }  
> },  
> "mappings": {  
> "Product": {  
> "properties": {  
> "categories": {  
> "type": "string",  
> "path": {  
> "type": "string",  
> "analyzer": "category\_path"  
> }  
> }  
> }  
> }  
> }  
> }

--

---

<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, 3:15am UTC](https://discuss.elastic.co/t/how-to-use-path-hierarchy-tokenizer/8496/3 "2017-07-06T03:15:41Z")

</div>


