Add tests around ElasticSearch#advanced_search

Tidy up the implementation while we're at it.