Add folderdepth in Path_hierarchy

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.