Output top pages and top ip of websites from our Grafana/Loki

Hi, our team is working on the output graph of our website (running in nginx). We have already been able to establish everything. Right now, we’re not yet able to output the top web pages, and top ip addresses from our logs. We’re not sure if we’re doing it right, please see details below. Thanks

our query:
topk(5, sum by (pages) (count_over_time({job=~"$job", pages="$pages"} [1m])))