方法 | Elasticsearch Jest 批量操作bug 根因定位排查

1、背景

使用Jest进行批量插入数据的时候,偶尔会出现如下的bug

One or more of the items in the Bulk request failed, check
BulkResult.getItems() for more information.

起初认为是偶发,就把并发数调小,就再没有关注。

2、出了事了,才找到根因。

当今天调试的时候,把批量数调到最小1的时候,ES中仍然没有导入数据。

这才意识到,不对,是不是单条数据就有问题?

后改到单条数据(不走批量),直接插入,报错如下:

单条导入报错如下:

[INFO]-[com.es.process.ESProcess] err
{“root_cause”:[{“type”:”mapper_parsing_exception”,”reason”:”Field
[_id] is a metadata field and cannot be added inside a document. Use
the index API request
parameters.”}],”type”:”mapper_parsing_exception”,”reason”:”Field [_id]
is a metadata field and cannot be added inside a document. Use the
index API request parameters.”}

比较直观,字段的问题。

逐个字段修复后,问题不在。

批量值改成较大值100后,也能较快导入。

扫描二维码关注公众号,回复: 1746069 查看本文章

3、走的弯路

3.1 源码附近找答案,无果。

Jest Bulk Github 源码位置:

if (isHttpSuccessful(statusCode)) {
    if(jsonMap.has("errors") && jsonMap.get("errors").getAsBoolean())
    {
        result.setSucceeded(false);
        result.setErrorMessage("One or more of the items in the Bulk request failed, check BulkResult.getItems() for more information.");
        log.debug("Bulk operation failed due to one or more failed actions within the Bulk request");
    } else {
        result.setSucceeded(true);
        log.debug("Bulk operation was successfull");
    }

源码中,有明确告诉:

批量操作失败,会打印Bulk operation failed错误。但是没有明确告诉,错在哪里?

更进一步,有告诉:

BulkResult.getItems() for more information

调试后,打印日志如下:

error = [io.searchbox.core. BulkResult B u l k R e s u l t I t e m @ 48782849 , i o . s e a r c h b o x . c o r e . B u l k R e s u l t BulkResultItem@6e2561df,
io.searchbox.core.BulkResult$BulkResultItem@1196e6ad,

貌似,还是没有根本错误的原因。

3.2 Google/Stackoverflow 查询

类似问题,匹配度少,无果。

3.3 想想可能出错的场景?

1、是不是要大量doc没有formerge导致的?

和这个没有本质关联。

2、是不是短时间内大量更新,导致的冲突。

不会的,ES是_version版本控制的。

3、是不是批量操作量太大了,超过队列长度大小。

逐步减少到1,才找到根本原因。

4、小结

1、批量的错误,要缩小范围调试,单条数据看有没有问题?

2、跟踪排查,转化思路,不放弃,直到定位本质原因。

加入知识星球,更短时间更快习得更多干货!
加入知识星球,更短时间更快习得更多干货!

2018-05-25 22:47 思于家中床前

作者:铭毅天下
转载请标明出处,原文地址:
http://blog.csdn.net/laoyang360/article/details/52244917
如果感觉本文对您有帮助,请点击‘顶’支持一下,您的支持是我坚持写作最大的动力,谢谢!

猜你喜欢

转载自blog.csdn.net/wojiushiwo987/article/details/80457798