/** * match_all 查询所有 */ @Test public void test02() throws IOException { SearchRequest searchRequest = new SearchRequest("hotel"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.matchAllQuery()); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); SearchHits searchHits = searchResponse.getHits(); System.out.println("查询总条数:" + searchHits.getTotalHits().value); SearchHit[] hits = searchHits.getHits(); for (SearchHit hit : hits) { HotelDoc hotelDoc = JSON.parseObject(hit.getSourceAsString(), HotelDoc.class); System.out.println("数据:" + hotelDoc); } }
标签:hotelDoc,searchSourceBuilder,searchHits,searchRequest,查询,ElasticSearch,match From: https://www.cnblogs.com/Rover20230226/p/17498903.html