Group by substring of term

Hi all,
I have a log in ElasticSearch with these fields: response-time, uri, path.
I need to calculate average response-time and group by on substring (uri,path), showing in a table panel.

Example:

response-time: 10
uri: /example/test/key/1234/
path: /key/1234

response-time: 20
uri: /example/test/key/789/
path: /key/789

substring (uri,path) is always /example/test so the response-time values must be used to calculate average value of /example/test record.

I try with group by Terms but I can put only exactly field names…
Can anyone help me?