Parsing string in query

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

/dir1/sub1/subsub1/file1
/dir1/sub1/subsub2/file2
/dir1/sub2/file3

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

sub1
sub2

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.