/** * term 精确查询 */ @Test public void test03() throws IOException { SearchRequest searchRequest = new SearchRequest(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.termQuery("brand","万怡")); 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); } }
标签:term,hotelDoc,searchSourceBuilder,searchHits,searchRequest,查询,ElasticSearch From: https://www.cnblogs.com/Rover20230226/p/17498909.html