ElasticSearch updates are not immediate, how do you wait for ElasticSearch to finish updating it's index?

前端 未结 4 449
耶瑟儿~
耶瑟儿~ 2020-12-16 11:13

I\'m attempting to improve performance on a suite that tests against ElasticSearch.

The tests take a long time because Elasticsearch does not update it\'s indexes i

4条回答
  •  萌比男神i
    2020-12-16 11:46

    As of version 5.0.0, elasticsearch has an option:

     ?refresh=wait_for
    

    on the Index, Update, Delete, and Bulk api's. This way, the request won't receive a response until the result is visible in ElasticSearch. (Yay!)

    See https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-refresh.html for more information.

    edit: It seems that this functionality is already part of the latest Python elasticsearch api: https://elasticsearch-py.readthedocs.io/en/master/api.html#elasticsearch.Elasticsearch.index

    Change your elasticsearch.update to:

    elasticsearch.update(
         index='blog',
         doc_type='blog'
         id=1,
         refresh='wait_for',
         body={
            ....
        }
    )
    

    and you shouldn't need any sleep or polling.

提交回复
热议问题