我正在使用golang编写一个工具,可以分别搜索有关userId列表的相关信息。每搜索 500 次,程序就会停止并显示“elastic: Error 500 (Internal Server Error): all shards failed [type=search_phase_execution_exception]”。大约5分钟后我可以继续接下来的500次搜索。我想知道为什么会发生这种情况。
就我而言,错误是因为在我的 ES 查询中,我在 ES 文档的
_id
字段上使用聚合。如果不设置该字段,ES会自动设置。无论如何,您最终都会遇到这个暂时性错误。
elastic: Error 500 (Internal Server Error): all shards failed [type=search_phase_execution_exception]
一直运行良好,直到应用程序使用量增长且文档数量增加到 20 万份。
解决方案: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-id-field.html
_id 字段被限制用于聚合、排序和 脚本编写。如果对 _id 字段进行排序或聚合 必填,建议将_id字段的内容复制到 另一个启用了 doc_values 的字段。
PS:我使用的是ES版本8.x.x。