# QueryBuilders rangeQuery with null date or values

**URL:** <https://discuss.elastic.co/t/querybuilders-rangequery-with-null-date-or-values/199931>\
**Category:** Elasticsearch\
**Created:** [September 18, 2019, 7:25am UTC](https://discuss.elastic.co/t/querybuilders-rangequery-with-null-date-or-values/199931 "2019-09-18T07:25:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Rod](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_rod/32/44993_2.png) [@Daniel\_Rod](https://discuss.elastic.co/u/Daniel_Rod)\
**Post date:** [September 18, 2019, 7:25am UTC](https://discuss.elastic.co/t/querybuilders-rangequery-with-null-date-or-values/199931/1 "2019-09-18T07:25:42Z")

</div>

Hello!

trying to found a solution for range query  
using QueryBuilders.rangeQuery

Problem:  
DateFrom can be null or higher than today  
DateTill can be null or smaller than today  
quantyti remaining can be null or value can be higher than 0

only then documents must appear in search results i was trying to solve this problem with

```
      //Query Mean - quantityRemaining must to be null or higher than 1
    publishedFilter
        .should(QueryBuilders.boolQuery()
            .mustNot(QueryBuilders.existsQuery(SearchAble.QUANTITY_REMAINING)))
        .should(QueryBuilders.rangeQuery(SearchAble.QUANTITY_REMAINING).gte(1))
        .minimumShouldMatch(1);

    QueryBuilders.boolQuery()
        .must(QueryBuilders.rangeQuery(SearchAble.DATE_TIME_FROM).lte(time))
        .mustNot(QueryBuilders.rangeQuery(SearchAble.DATE_TIME_TILL).lte(time));

```

but this solution working only for quantyti remaining instead of the dateFrom and dateTill

any ideas ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 16, 2019, 7:25am UTC](https://discuss.elastic.co/t/querybuilders-rangequery-with-null-date-or-values/199931/2 "2019-10-16T07:25:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
