zoukankan      html  css  js  c++  java
  • elasticSearch RangeQuery范围查询from to的理解

    elasticSearch RangeQuery范围查询from to的理解

    Elasticsearch Guide 选择版本号来查询对应的文档内容:
    https://www.elastic.co/guide/en/elasticsearch/reference/6.7/index.html

     

    需要根据版本号来查询:
    Elasticsearch Guide [6.7] Query DSL Term level queries Range Query
    https://www.elastic.co/guide/en/elasticsearch/reference/6.7/query-dsl-range-query.html

    查看RangeQueryBuilder.java源码内容:
    public static final boolean DEFAULT_INCLUDE_UPPER = true; //默认是包含
    public static final boolean DEFAULT_INCLUDE_LOWER = true; //默认是包含

    private boolean includeLower = DEFAULT_INCLUDE_LOWER;
    private boolean includeUpper = DEFAULT_INCLUDE_UPPER;

    /**
    * The from part of the range query. Null indicates unbounded. 默认是包含(大于等于)
    */
    public RangeQueryBuilder from(Object from) {
    return from(from, this.includeLower);
    }

    /**
    * The from part of the range query. Null indicates unbounded. 大于
    */
    public RangeQueryBuilder gt(Object from) {
    return from(from, false);
    }

    /**
    * The from part of the range query. Null indicates unbounded. 大于等于
    */
    public RangeQueryBuilder gte(Object from) {
    return from(from, true);
    }


    /**
    * The to part of the range query. Null indicates unbounded. 默认是包含(小于等于)
    */
    public RangeQueryBuilder to(Object to) {
    return to(to, this.includeUpper);
    }

    /**
    * The to part of the range query. Null indicates unbounded. 小于
    */
    public RangeQueryBuilder lt(Object to) {
    return to(to, false);
    }

    /**
    * The to part of the range query. Null indicates unbounded. 小于等于
    */
    public RangeQueryBuilder lte(Object to) {
    return to(to, true);
    }

    demo代码(三种方式):
    boolQueryBuilder.must(QueryBuilders.rangeQuery("field1").to(reqVO.getDate2()));
    boolQueryBuilder.must(QueryBuilders.rangeQuery("field2").from(reqVO.getDate1()));
    boolQueryBuilder.must(QueryBuilders.rangeQuery("field2").from(reqVO.getDate1())).to(reqVO.getDate2()));

  • 相关阅读:
    Netty学习(四)-TCP粘包和拆包
    Netty学习(三)-Netty重要接口讲解
    Netty学习(二)-Helloworld Netty
    Netty学习(一)-为什么选择Netty
    java学习-NIO(五)NIO学习总结以及NIO新特性介绍
    java学习-NIO(四)Selector
    哈希表 HashTable(又名散列表)
    设计模式-外观模式
    设计模式-装饰模式
    设计模式-适配器模式
  • 原文地址:https://www.cnblogs.com/oktokeep/p/15475327.html
Copyright © 2011-2022 走看看