大數據技術之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)結果查看