# Quering nullable timstamp field

**URL:** <https://discuss.elastic.co/t/quering-nullable-timstamp-field/240478>\
**Category:** Elasticsearch\
**Created:** [July 9, 2020, 7:51am UTC](https://discuss.elastic.co/t/quering-nullable-timstamp-field/240478 "2020-07-09T07:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![recordable542](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/recordable542/32/69082_2.png) [@recordable542](https://discuss.elastic.co/u/recordable542)\
**Post date:** [July 9, 2020, 7:51am UTC](https://discuss.elastic.co/t/quering-nullable-timstamp-field/240478/1 "2020-07-09T07:51:30Z")

</div>

I have `user` index like below

```auto
name: text
frozen_until: timestamp

```

I want to query all users which...  
(frozen\_until == null || frozen\_until \< today)

below is the query I'm struggling with:

```auto
{
	"query": {
		"bool": {
			"should": [{
				"bool": { 
					"must_not": {
						"exists": {
							"field": "frozen_until"
						}
					}
				}
			},
			{
				"filter": {
					"range": {
						"frozen_until": {
							"lte": "now/d"
						}
					}
				}
			}
			],
			"minimum_should_match": 1
		}
	}
}

```

error message: ` "reason": "[14:14] [bool] failed to parse field [should]",`

how can I use range filter inside should?

---

<div class="post-metadata">

**Author:** ![Vinayak\_Sapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_sapre/32/45939_2.png) [@Vinayak\_Sapre](https://discuss.elastic.co/u/Vinayak_Sapre)\
**Post date:** [July 9, 2020, 8:55am UTC](https://discuss.elastic.co/t/quering-nullable-timstamp-field/240478/2 "2020-07-09T08:55:28Z")

</div>

Remove "filter" line. Try this

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must_not": {
              "exists": {
                "field": "frozen_until"
              }
            }
          }
        },
        {
          "range": {
            "frozen_until": {
              "lte": "now"
            }
          }
        }
      ]
    }
  }
}

```

---

<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 6, 2020, 8:55am UTC](https://discuss.elastic.co/t/quering-nullable-timstamp-field/240478/3 "2020-08-06T08:55:30Z")

</div>

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