Nginx-Loki, request_uri, with the most long upstream_response_time

Hello!

My setup:

Grafana Version: 9.1.1

Loki: Version: 2.8.2

I am parsing nginx logs with json. For example:

{"remote_addr": "1.1.1.1", "time_local": "12/Jun/2023:12:10:07 +0000", "request": "GET /example/uri HTTP/1.1", "request_uri": "/example/uri", "status": "200", "bytes_sent": "625", "request_time": "0.320", "upstream_response_time": "0.320", }

My goal: to get the request_uri, with the most long upstream_response_time, for example for the last 5 minutes. I want to know which request takes the longest to process.

I want to see something like this:

/example/uri - 1.234
/example/uri2 - 1.231
etc…

I checked many different queries, but nothing is working. For example:

topk(10, avg_over_time({job=~"$job"} | json | unwrap upstream_response_time | __error__="" [$__interval])) by (request_uri)

Has anyone had to deal with such a request and requirements?

Thank you!