// 1.创建客户端对象 RestHighLevelClient client = new RestHighLevelClient( RestClient.builder(new HttpHost("localhost", 9200, "http")) );
(1)创建索引
// 创建索引 - 请求对象 CreateIndexRequest request = new CreateIndexRequest("user");
// 发送请求,获取响应 CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); boolean acknowledged = response.isAcknowledged();
// 响应状态 System.out.println("操作状态 = " + acknowledged);
(2)查看索引
// 查询索引 - 请求对象 GetIndexRequest request = new GetIndexRequest("user"); // 发送请求,获取响应 GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT); System.out.println("aliases:"+response.getAliases()); System.out.println("mappings:"+response.getMappings()); System.out.println("settings:"+response.getSettings());
(3)删除索引
// 删除索引 - 请求对象 DeleteIndexRequest request = new DeleteIndexRequest("user");
// 发送请求,获取响应 AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT);文章来源:https://www.toymoban.com/news/detail-640157.html
// 操作结果 System.out.println("操作结果 : " + response.isAcknowledged());文章来源地址https://www.toymoban.com/news/detail-640157.html
到了这里,关于Es的索引操作(代码中的基本操作)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!