elasticSearch RangeQuery范围查询from to的理解

2024-10-09 08:11:41 浏览数 (3)

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()));

0 人点赞