gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:22:50 27 4
gpt4 key购买 nike

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

当我更新时,我这样做:

  • 我首先搜索文档,并为返回的结果设置了更大的限制(例如,大小: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/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com