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的主要内容,如果未能解决你的问题,请参考以下文章

elasticsearch 5.x 给定时间范围查询数据

Elasticsearch操作

Elasticsearch系列(12)Query之复合查询

Elasticsearch学习笔记-DSL查询文档

elasticsearch怎么根据term和range查询

Elasticsearch 的新 range 丰富策略使上下文数据分析更上一层楼 - 7.16