问题:
使用 org.elasticsearch.client.RestHighLevelClient#bulk,BulkRequest添加的是IndexRequest,发现无法更新索引。
原因:
IndexRequest设定添加文档,
UpdateRequest设定更新文档,
设定upsert执行有则修改无则更新(upsert类型更新,文档不存在时创建)
解决:
private UpdateRequest buildUpdateRequest(JSONObject json, String realIndexName) { UpdateRequest updateRequest = new UpdateRequest(realIndexName, "_doc", json.getString("id")); Map<String, Object> doc = Maps.newHashMap(); for (String key : json.keySet()) { doc.put(camelToUnderscoreConverter.convert(key), json.get(key)); } // upsert更新 updateRequest.doc(doc).upsert(); return updateRequest; }
标签:doc,IndexRequest,UpdateRequest,json,updateRequest,upsert From: https://www.cnblogs.com/parkdifferent/p/17230960.html