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