ES bulk 批量操做

bulk容许在一个请求中进行多个操做(create、index、update、delete),也就是能够在一次请求裡作不少事情elasticsearch

也因为这个关系,所以bulk的请求体和其余请求的格式会有点不一样spa

bulk的请求模板code

分红action、metadata和doc三部份blog

action : 必须是如下4种选项之一ip

  index(最经常使用) : 若是文档不存在就建立他,若是文档存在就更新他文档

  create : 若是文档不存在就建立他,但若是文档存在就返回错误源码

  使用时必定要在metadata设置_id值,他才能去判断这个文档是否存在it

  update : 更新一个文档,若是文档不存在就返回错误pip

  使用时也要给_id值,且后面文档的格式和其余人不同io

  delete : 删除一个文档,若是要删除的文档id不存在,就返回错误

使用时也必须在metadata中设置文档_id,且后面不能带一个doc,由于没意义,他是用_id去删除文档的

metadata : 设置这个文档的metadata,像是_id、_index、_type...

doc : 就是通常的文档格式

 

 

bulk 若是一次性数据过多,很容易致使超时 

elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='192.168.0.92', port='9200'): Read timed out. (read timeout=10))

 

查看bulk 源码发现

 

@query_params('_source', '_source_exclude', '_source_include', 'fields',
        'pipeline', 'refresh', 'routing', 'timeout', 'wait_for_active_shards')
    def bulk(self, body, index=None, doc_type=None, params=None):

有个timeout参数,能够设置超时时间,默认是10s

bulk(es, actions, request_timeout=100)

相关文章
相关标签/搜索