rang 范围查询ElasticSearch
Posted Rover20230226
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rang 范围查询ElasticSearch相关的知识,希望对你有一定的参考价值。
/** * rang 范围查询 */ @Test public void test04() throws IOException SearchRequest searchRequest = new SearchRequest(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.rangeQuery("price").gt(1000).lt(3000)); 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);
以上是关于rang 范围查询ElasticSearch的主要内容,如果未能解决你的问题,请参考以下文章