package demo;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;
import java.io.IOException;
public class TestElasticSearch2 {
public static void main(String[] args) throws IOException {
//创建客户端对象
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", 9200, "http"))
);
//查询索引
GetIndexRequest request = new GetIndexRequest("user");
//发送请求,获取响应
GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
//响应状态
System.out.println("别名:"+response.getAliases());
System.out.println("映射:"+response.getMappings());
System.out.println("设置:"+response.getSettings());
//关闭客户端连接
client.close();
}
}