ES添加文档 踩坑之 —— The number of object passed must be even but was [1]

 

读取文件,获取json格式的数据doc,

然后使用 bulkRequestBuilder.add(client.prepareIndex(index, type, id).setSource(doc));

往ES中批量插入文档,接着就报下面这个异常错误:

java.lang.IllegalArgumentException: The number of object passed must be even but was [1]

 

后来,花了点时间,才查到原因:

ES 变更版本后,此处代码不适用,会报  The number of object passed must be even but was [1] 这个异常

bulkRequestBuilder.add(client.prepareIndex(index, type, id).setSource(doc)); 中的 setSource()的参数不能是json串了

但是可以转化成 map 来使用 

 

共同学习,共同进步,若有补充,欢迎指出,谢谢!

 

转载于:https://www.cnblogs.com/dengguangxue/p/10577123.html

你可能感兴趣的:(ES添加文档 踩坑之 —— The number of object passed must be even but was [1])