try {
val request = BulkRequest(indexNmae)
request.timeout("${timeout}s")
request.estimatedSizeInBytes()
list.forEach {
var id=""
if(it.containsKey("_id")){
id = it.getString("_id")
it.remove("_id")
}
request.add(
IndexRequest()
.source(it.toJSONString(), XContentType.JSON).id(id)
)
}
//客户端执行批量操作
val response = client.bulk(request, RequestOptions.DEFAULT)
println(response.status())
} catch (e: IOException) {
e.printStackTrace()
}