public class ESTest_Doc_Query {
public static void main(String[] args) throws Exception {
//创建ES客户端
RestHighLevelClient esClient = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost",9200,"http"))
);
//1、查询索引中全部数据
SearchRequest request = new SearchRequest();
request.indices("user");
request.source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()));
SearchResponse response = esClient.search(request, RequestOptions.DEFAULT);
SearchHits hits = response.getHits();
System.out.println(hits.getTotalHits());
System.out.println(response.getTook());
for(SearchHit hit : hits){
System.out.println(hit.getSourceAsString());
}
//关闭ES客户端
esClient.close();
}
}