Elasticsearch High Level Rest Client 基本增删改查

RestClient restClient = RestClient.builder(new HttpHost("localhost",9200,"http")).build();

RestHighLevelClient highLevelClient = new RestHighLevelClient(restClient);

 

//增, source 里对象创建方式可以是JSON字符串,或者Map,或者XContentBuilder 对象

IndexRequest indexRequest = new IndexRequest("index", "type", "ID").source(builder);

highLevelClient.index(indexRequest);

 

//删

DeleteRequest deleteRequest = new DeleteRequest("index", "type", "ID");

highLevelClient.delete(deleteRequest);

 

//改, source 里对象创建方式可以是JSON字符串,或者Map,或者XContentBuilder 对象

UpdateRequest updateRequest = new UpdateRequest("index", "type", "ID").doc(builder);

highLevelClient.update(updateRequest);

 

//查

GetRequest getRequest = new GetRequest("index", "type", "ID");

highLevelClient.get(getRequest);

你可能感兴趣的:(es)