Hi
Based on my research, the bad gateway error is usually caused by that your query returns too much data. The gateway is limited to 8MB of data, period.
You can limit the time range by setting timespan to fix this issue, there is a similar thread for your reference.
Thanks,
Lydia Zhang