我使用脚本进行批量更新来更新嵌套字段,但这非常慢:
POST index/type/_bulk
{"update":{"_id":"1"}}
{"script"{"inline":"ctx._source.nestedfield.add(params.nestedfield)","params":{"nestedfield":{"field1":"1","field2":"2"}}}}
{"update":{"_id":"2"}}
{"script"{"inline":"ctx._source.nestedfield.add(params.nestedfield)","params":{"nestedfield":{"field1":"3","field2":"4"}}}}
... [a lot more splitted in several batches]
您知道另一种更快的方法吗?
似乎可以存储脚本以便不在每次更新时重复它,但我找不到保留“动态”参数的方法。
正如性能优化问题一样,没有单一的答案,因为导致性能不佳的可能原因有很多。
在你的情况下,你正在批量生产update
要求。当update
执行后,文档为实际上正在重新索引 https://www.elastic.co/guide/en/elasticsearch/guide/current/partial-updates.html:
...更新文档就是检索它、更改它,然后重新索引整个文档。
因此,看看是有意义的索引性能调整技巧 https://www.elastic.co/guide/en/elasticsearch/reference/5.6/tune-for-indexing-speed.html。在你的情况下我首先考虑的几件事是选择
正确的批量大小,使用多个线程进行批量请求并增加/禁用索引刷新间隔 https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index-modules.html#dynamic-index-settings.
您还可以考虑使用支持并行批量请求的现成客户端,例如Python Elasticsearch 客户端 http://elasticsearch-py.readthedocs.io/en/master/helpers.html?highlight=bulk does.
理想的做法是监控 ElasticSearch 性能指标,以了解瓶颈在哪里,以及您的性能调整是否带来了实际收益。Here https://www.datadoghq.com/blog/monitor-elasticsearch-performance-metrics/是一篇关于 ElasticSearch 性能指标的概述博客文章。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)