Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElasticSearch协程客户端批量插入问题 #560

Open
ArgoVesta opened this issue Sep 26, 2022 · 5 comments
Open

ElasticSearch协程客户端批量插入问题 #560

ArgoVesta opened this issue Sep 26, 2022 · 5 comments

Comments

@ArgoVesta
Copy link

elasticsearch批量写入,这里只会插入前10W条,新的却写入不进?(假如我sql里面写50W条,也可以写入,后面的却写不进去)

@XueSiLf
Copy link
Collaborator

XueSiLf commented Oct 12, 2022

你好,我是XueSi,很抱歉,之前太忙没有及时处理,今天我复现下这个问题然后再尝试修复。

@XueSiLf
Copy link
Collaborator

XueSiLf commented Oct 12, 2022

你好,我这边测试导入 20w 条数据时是正常的,使用 ElasticSearch 官方PHP客户端 导入 50w 条数据时也报异常。异常如下:

{"error":{"root_cause":[{"type":"es_rejected_execution_exception","reason":"rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=110388603, max_coordinating_and_primary_bytes=103887667]"}],"type":"es_rejected_execution_exception","reason":"rejected execution of coordinating operation [coordinating_and_primary_bytes=0, replica_bytes=0, all_bytes=0, coordinating_operation_bytes=110388603, max_coordinating_and_primary_bytes=103887667]"},"status":429}

根据异常提示应该是达到了内存上限,max_coordinating_and_primary_bytes是内存的10%,建议你进行分批导入。

@XueSiLf
Copy link
Collaborator

XueSiLf commented Oct 12, 2022

其实本质还是取决于你这10w条数据占用的大小,导入大量数据时非常吃内存的,特别是bulk这种操作,也会导致ElasticSearch服务端线程池占满,从而导致 ElasticSearch 拒绝响应。所以建议你分批导入,例如每次导入10w 或者 20w。
针对导入失败的情况你需要查看原因:
查看原因,统一导入成功和失败的代码

$errorNums = 0;
$sucNums = 0;
foreach ($r['items'] as $row) {
    if (!empty($row['create'])) {
        $create = $row['create'];
        if (isset($create['error'])) {
            var_dump($create['error']['reason']);
            $errorNums += 1;
        } else if (isset($create['result']) && $create['result'] == 'created') {
            $sucNums += 1;
        }
    }
}

@XueSiLf
Copy link
Collaborator

XueSiLf commented Oct 12, 2022

你好有问题的话再QQ联系我

@ArgoVesta
Copy link
Author

好的,我试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants