elasticsearch - 如何使用Elasticsearch处理多个更新/删除?

标签 elasticsearch bulkinsert bulkupdate elasticsearch-bulk-api

我需要更新或删除几个文档。

当我更新时,我这样做:

  • 我首先搜索文档,并为返回的结果设置了更大的限制(例如,大小:10000)。
  • 对于每个返回的文档,我都会修改某些值。
  • 我很讨厌对整个修改后的列表(批量索引)进行elasticsearch。

  • 该操作一直进行到点1不再返回结果为止。

    当我删除时,我这样做:
  • 我首先搜索文档,为返回结果设置更大的限制(例如,大小:10000)
  • 我删除所有发现的发送到elasticsearch _id文档的文档(10000个请求)

  • 重复此操作,直到点1不再返回结果。

    这是进行更新的正确方法吗?

    删除时,是否可以发送多个ID一次删除多个文档?

    最佳答案

    对于删除和更新,如果要按ID删除或更新,可以使用批量api:

    Bulk API

    The bulk API makes it possible to perform many index/delete operations in a single API call. This can greatly increase the indexing speed.

    The possible actions are index, create, delete and update. index and create expect a source on the next line, and have the same semantics as the op_type parameter to the standard index API (i.e. create will fail if a document with the same index and type exists already, whereas index will add or replace a document as necessary). delete does not expect a source on the following line, and has the same semantics as the standard delete API. update expects that the partial doc, upsert and script and its options are specified on the next line.



    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html

    您也可以通过查询删除:

    Delete By Query API

    The delete by query API allows to delete documents from one or more indices and one or more types based on a query. The query can either be provided using a simple query string as a parameter, or using the Query DSL defined within the request body.



    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html

    关于elasticsearch - 如何使用Elasticsearch处理多个更新/删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25625066/

    相关文章:

    sql-server-2008 - 在INSERT INTO Table(选择SELECT * FROM Table2)过程中,如何在每个插入的行上触发触发器?

    python-3.x - 使用 Djangobulk_update() 时,“dict”对象没有属性 'pk'

    php - 使用 Laravel 复选框一次更新多个记录

    python - 使用 pyodbc 执行多个数据帧到 SQL Server

    insert - SQLAlchemy 原始 sql 与表达式语言语句

    java - 如何在 Hibernate 批量更新查询中使用日期对象

    spring-boot - 使用RestHighLevelClient进行 Elasticsearch 时获取connectionexception

    java - Elasticsearch java中带有not_analyzed的索引字段

    elasticsearch - Kibana-缺少报告功能

    json - 使用 bash 脚本在超过硬盘大小时自动清除 Elasticsearch 索引