大数据技术之Elasticsearch-Java API操作(二)条件查询QueryBuilder
查询所有(matchAllQuery)
1)源代码
@Test public void matchAllQuery() {
// 1 执行查询 SearchResponse searchResponse = client.prepareSearch("blog").setTypes("article") .setQuery(QueryBuilders.matchAllQuery()).get();
// 2 打印查询结果 SearchHits hits = searchResponse.getHits(); // 获取命中次数,查询结果有多少对象 System.out.println("查询结果有:" + hits.getTotalHits() + "条");
for (SearchHit hit : hits) {
// 3 关闭连接 client.close(); } |
2)结果查看