Python script update by query elasticsearch doesn't work

Solution:

Reference:

I made this change to my python code and it worked:

I added self.es.indices.refresh(index = i)

if self.es.indices.exists(index = i):
            for q in queries:
                self.es.indices.refresh(index = i)
                self.es.update_by_query(index = i, body = q)