# Add folderdepth in Path\_hierarchy

**URL:** <https://discuss.elastic.co/t/add-folderdepth-in-path-hierarchy/41991>\
**Category:** Elasticsearch\
**Created:** [February 17, 2016, 9:31am UTC](https://discuss.elastic.co/t/add-folderdepth-in-path-hierarchy/41991 "2016-02-17T09:31:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaviSidhu](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@RaviSidhu](https://discuss.elastic.co/u/RaviSidhu)\
**Post date:** [February 17, 2016, 9:31am UTC](https://discuss.elastic.co/t/add-folderdepth-in-path-hierarchy/41991/1 "2016-02-17T09:31:57Z")

</div>

I have a query regarding the "transform" element in ES template mapping. I have been trying to figure out ways to add pathlevel to tokens generated by path\_hierarchy tokenizer.

Say I have a value like -

/a/b/c

path hierarchy gives me

/a  
/a/b  
/a/b/c

But I want to add pathlevel to it. I came across this piece while googling -

"transform": {  
"lang": "groovy",  
"script": "def splitPath = [];splitPath = ctx.\_source['request'].split('/'); ctx.\_source['pathDepth'] =splitPath.length; for (i = 1; splitPath.length \> i; i++) { ctx.\_source['pathLevel' + i] =splitPath[i] }"  
},

I thought I could use it for my case. But it errors out with -  
"error"=\>{"type"=\>"mapper\_parsing\_exception", "reason"=\>"Failed to parse mapping [dummy\_temp]: No type specified for field [transform]"  
This is the mapping I have

"request": {  
"type": "string",  
"index": "not\_analayzed",  
"fields": {  
"tree": {  
"type": "string",  
"analyzer": "analyzer\_path\_tokens",

"analyzer": "analyzer\_path\_tokens"  
},

This is the analyzer definition

"analyzer": {  
"analyzer\_path\_tokens": {  
"type": "custom",  
"tokenizer": "path\_hierarchy"  
}  
}

Please advise.

---

<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 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/add-folderdepth-in-path-hierarchy/41991/2 "2017-07-05T23:15:47Z")

</div>


