下面记录来记录并分享ES相关操作:
单个文件更新实现方式如下所示:
/**
* create by wxy_jdhk
*/
public class ElasticSearchUtils {
//更新方式1
public void updateDocumentOne(TransportClient client) {
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index("index");
updateRequest.type("_doc");
updateRequest.id("1");
try {
updateRequest.doc(
jsonBuilder()
.startObject()
.field("gender", "male")
.endObject()
);
UpdateResponse response = client.update(updateRequest).get();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
//更新方式2
public void updateDocumentTwo(TransportClient client) {
/*client.prepareUpdate("tt1", "_doc", "1")
.setScript(new Script(
"ctx._source.gender = \"male\"",
ScriptService.Sc