Just one information about your solution to refresh the index before each query, you need to know about the cost of a refresh call.
http://blog.mikemccandless.com/ <--- this blog a little bit old but have a lot of resources about how lucene work.
Knowing that and to prevent run unnecessary refresh can be keep the code as before and add a try catch if the exception is a ConflictError
so you can run a refresh and call again your update.
something like:
from elasticsearch.exceptions import ConflictError
if self.es.indices.exists(index = i):
for q in queries:
try:
self.es.update_by_query(index = i, body = q)
except ConflictError as e:
# a conflict exception is raised more info here: https://discuss.elastic.co/t/python-script-update-by-query-elasticsearch-doesnt-work
self.es.indices.refresh(index = i)
# try again
self.es.update_by_query(index = i, body = q)