504 Error due to large number of routing parameters

We have a large number of shards. The documents are routed using user ids. There are use cases where we need to search across multiple users. When we specify a large number of user ids as the routing parameter, we see a 504 error. I think this is because it is going beyond the limit of max URL length. Is there a way we can specify the routing parameter in the request body instead of the URL?

If you are specifying a lot of routing parameters you may be fine querying all shards without routing as you will be hitting a lot of shards anyway. Can you try this?

That works. But the query takes a longer time as it is hitting a very large number of shards(500). With the routing parameters, it is still limited to 40-50 shards only. So, it would be good if there is a way to pass this as a request body.