My guess is that this might have something to do with the changes to the queries in 5.x
https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_search_changes.html
Easiest way to see what's changed (because that's a very big list there) is to recreate the query in 5.x and compare the two exported objects.