Parsing string in query

I am asking for help for a query in ElasticSearch. I have entries in field "name" like:


Here I want to list objects in a specific directory. For example if I search by /dir1 I want to be returned:


or entire "name" string but subdirectories shall not be repeated. I can use grouping but a problem is a parsing of string itself. Can anyone help me with this? Thank you.

I would look at PathTokenizer.