# Query for end date greater than now or doesn't exist not working

**URL:** <https://discuss.elastic.co/t/query-for-end-date-greater-than-now-or-doesnt-exist-not-working/310361>\
**Category:** Elasticsearch\
**Created:** [July 22, 2022, 3:43am UTC](https://discuss.elastic.co/t/query-for-end-date-greater-than-now-or-doesnt-exist-not-working/310361 "2022-07-22T03:43:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ellie\_Y](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ellie_y/32/78183_2.png) [@Ellie\_Y](https://discuss.elastic.co/u/Ellie_Y)\
**Post date:** [July 22, 2022, 3:43am UTC](https://discuss.elastic.co/t/query-for-end-date-greater-than-now-or-doesnt-exist-not-working/310361/1 "2022-07-22T03:43:40Z")

</div>

My 'must' query works fine but the should returns the following error:  
"No query registered for [exists]"

I want to find documents that either do not have a stopPublishDate or if they do have one the date must be in the future/ greater than 'now'.

```auto

 requestBody = {
    "size": 1000,
    "query": {
      "bool": {

        "must": [
          {
            "match": {
              "_TypeShortName": "AlertPage"
            }
          },
          {
            "term": {
              'IsDeleted$$bool': false
            }
          },
          {
            "range": {
              'StartPublish$$date': {
                'lte': 'now'
              }
            }
          }
        ],

        "should": [
          {
            "range": {
              "StopPublish$$date": {
                "gte": 'now'
              }
            }
          },
          {
            "bool": {
              "must_not": [
                {
                  "exists": {
                    "field": "StopPublish$$date"
                  }
                }
              ]
            }
          }

        ]

      }

    }
  }

```

---

<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:** [August 19, 2022, 3:44am UTC](https://discuss.elastic.co/t/query-for-end-date-greater-than-now-or-doesnt-exist-not-working/310361/2 "2022-08-19T03:44:08Z")

</div>

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