问题。我的任务是研究如何在 Elasticsearch 中回填数据。到目前为止有点空。基本要点是:
注意:所有文档都存储在每日索引下,每天约有 20 万个文档。
- 我需要能够重新索引大约 60 天的数据。
- 我需要为每个文档 payload.time_sec 和 payload.time_nanosec 取两个字段,取值并对它们进行一些数学计算 (time_sec * 10**9 + time_nanosec),然后将其作为单个字段返回到重新索引的文件
我正在查看带有批量助手的 Python API 文档: http://elasticsearch-py.readthedocs.io/en/master/helpers.html
但我想知道这是否可能。
我的想法是使用: 批量助手拉动滚动 ID(批量更新?),遍历每个文档 ID,从每个停靠栏的两个字段中拉取数据,进行数学计算,并使用新的字段数据完成更新请求。
有人做过吗?也许是带有 groovy 脚本的东西?
谢谢!
请您参考如下方法:
Bulk helpers to pull a scroll ID (bulk _update?), iterate over each doc id, pull that data in from the two fields for each dock, do the math, and finish the update request with the new field data.
基本上,是的:
- 使用
/_search?scroll获取文档 - 执行您的操作
- 发送
/_bulk更新请求
其他选项是:
- use the
/_reindexAPI
如果你不想创建一个新的索引,可能不太好 - use the
/_update_by_queryAPI
两者都支持脚本,如果我理解正确的话,这将是完美的选择,因为您的更新不依赖于外部因素,所以这也可以直接在服务器内完成。
