RestHighLevelClient使用记录
作者:互联网
RestHighLevelClient使用记录
新增
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new IndexRequest(index).id(id).source(JSON.toJSONString(author, serializeConfig), XContentType.JSON));
BulkResponse bulk = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
整体更新
UpdateRequest updateRequest = new UpdateRequest(index, id);
updateRequest.doc(JSON.toJSONString(author, serializeConfig), XContentType.JSON);
UpdateResponse updateResponse = restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
局部更新
// 构建更新参数
Map<String, Object> params = new HashMap<>();
params.put("analysis", JSON.toJSON(response.getResults()));
UpdateByQueryRequest request = new UpdateByQueryRequest(index);
// 更新条件
request.setQuery(new TermQueryBuilder("mid", mid));
// 最大更新文档树
request.setMaxDocs(1);
// 更新字段,多个用;隔开
request.setScript(new Script(ScriptType.INLINE, "painless", "ctx._source.analysis = params.analysis", params)));
BulkByScrollResponse response = restHighLevelClient.updateByQuery(request, RequestOptions.DEFAULT);
标签:记录,DEFAULT,request,更新,JSON,params,使用,new,RestHighLevelClient 来源: https://blog.csdn.net/qq_39604170/article/details/121656776