QueryBuilders.rangeQuery 川长思鸟来 2022-10-13 01:54 163阅读 0赞 数字范围查询 //闭区间查询 QueryBuilder qb1 = QueryBuilders.rangeQuery("${fieldName}").from(${fieldValue1}).to(${fieldValue2}); //开区间查询 QueryBuilder qb1 = QueryBuilders.rangeQuery("${fieldName}").from(${fieldValue1}, false).to(${fieldValue2}, false); //大于 QueryBuilder qb1 = QueryBuilders.rangeQuery("${fieldName}").gt(${fieldValue}); //大于等于 QueryBuilder qb1 = QueryBuilders.rangeQuery("${fieldName}").gte(${fieldValue}); //小于 QueryBuilder qb1 = QueryBuilders.rangeQuery("${fieldName}").lt(${fieldValue}); //小于等于 QueryBuilder qb1 = QueryBuilders.rangeQuery("${fieldName}").lte(${fieldValue}); 生产实例使用: // 增加价格区间的检索条件 if (searchRequest.getMinPrice() != null) { queryBuilder.must(QueryBuilders.rangeQuery(avagePriceStr) .from(searchRequest.getMinPrice().toString()).includeLower(true) .includeUpper(true)); } if (searchRequest.getMaxPrice() != null) { queryBuilder.must(QueryBuilders.rangeQuery(avagePriceStr) .to(searchRequest.getMaxPrice().add(new BigDecimal(1)).toString()) .includeUpper(false)); }
还没有评论,来说两句吧...