I spent the past day thinking about this, I don’t think we have a good solution for you that exists right now. You might be best served by writing a simple plugin that does it. Extending Caddy — Caddy Documentation
We’re adding a bunch of ways to rewrite the query in the next version, but I don’t think any of the operations we’re adding will do what you need Query rewrite operations · Issue #6096 · caddyserver/caddy · GitHub. What you’re trying to do is a pretty specialized case, so a plugin is likely your best option.
Do you not control your upstream app? Why can’t you filter the query in your app itself?