# Date range not working ... no errors but no matches

**URL:** <https://discuss.elastic.co/t/date-range-not-working-no-errors-but-no-matches/217801>\
**Category:** Elasticsearch\
**Created:** [February 4, 2020, 12:30pm UTC](https://discuss.elastic.co/t/date-range-not-working-no-errors-but-no-matches/217801 "2020-02-04T12:30:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jagdeepak\_Rawat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jagdeepak_rawat/32/54603_2.png) [@Jagdeepak\_Rawat](https://discuss.elastic.co/u/Jagdeepak_Rawat)\
**Post date:** [February 4, 2020, 12:30pm UTC](https://discuss.elastic.co/t/date-range-not-working-no-errors-but-no-matches/217801/1 "2020-02-04T12:30:33Z")

</div>

I put the following json in elasticsearch under an index.  
but can't use date ranges on this structure even though I have put custom mappings of my own to show where date is.

{  
"key": {  
"window\_end": 1579602460000,  
"window\_start": 1579602400000,  
"window\_start\_ins": "2020-01-21T10:26:40.000Z",  
"window\_end\_ins": "2020-01-21T10:27:40.000Z",  
"key": [  
{  
"field": "$\_log\_event",  
"value": "ALERT"  
}  
]  
},  
"value": [  
{  
"field": "REQUEST",  
"type": "count",  
"value": 565584  
},  
{  
"field": "fatal\_cost",  
"type": "sum",  
"value": 281509  
},  
{  
"field": "min\_cost",  
"type": "min",  
"value": 44  
},  
{  
"field": "drop\_cost",  
"type": "sum",  
"value": 131377  
},  
{  
"field": "FATAL",  
"type": "count",  
"value": 291  
},  
{  
"field": "DROP",  
"type": "count",  
"value": 284  
},  
{  
"field": "max\_cost",  
"type": "max",  
"value": 326601  
}  
]  
}

this is my mapping object.  
{  
"reporting\_test1" : {  
"mappings" : {  
"properties" : {  
"key" : {  
"type" : "nested",  
"properties" : {  
"key" : {  
"type" : "nested",  
"properties" : {  
"field" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"value" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
}  
}  
},  
"window\_end" : {  
"type" : "long"  
},  
"window\_end\_ins" : {  
"type" : "date"  
},  
"window\_start" : {  
"type" : "long"  
},  
"window\_start\_ins" : {  
"type" : "date"  
}  
}  
},  
"value" : {  
"type" : "nested",  
"properties" : {  
"field" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"type" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"value" : {  
"type" : "long"  
}  
}  
}  
}  
}  
}  
}

and I am giving query.

GET reporting\_test1/\_search  
{  
"query": {"range": {  
"key.window\_end\_ins": {  
"gte": "2010-01-01T00:00:00",  
"lte": "now"  
}  
}  
}  
}

the response is following: -  
{  
"took" : 0,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : {  
"value" : 0,  
"relation" : "eq"  
},  
"max\_score" : null,  
"hits" :   
}  
}

even after trying different date formats. it doesn't work.  
also in kibana it doesn't give any output because no date query ever gives any hits back.  
please can somebody point out why is it not working?

---

<div class="post-metadata">

**Author:** ![Magnus\_Kessler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnus_kessler/32/42001_2.png) [@Magnus\_Kessler](https://discuss.elastic.co/u/Magnus_Kessler)\
**Post date:** [February 4, 2020, 5:34pm UTC](https://discuss.elastic.co/t/date-range-not-working-no-errors-but-no-matches/217801/2 "2020-02-04T17:34:03Z")

</div>

Your `key` field is mapped as `nested`. Nested fields can only be queried with [nested queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html).

Be aware that Kibana hasn't yet got any good support for nested queries.

Please read the documentation for the [nested datatype](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html). It explains when it should be used. In your example, you could simply map the top-level `key` field as a JSON object, and query it with standard queries.

---

<div class="post-metadata">

**Author:** ![Jagdeepak\_Rawat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jagdeepak_rawat/32/54603_2.png) [@Jagdeepak\_Rawat](https://discuss.elastic.co/u/Jagdeepak_Rawat)\
**Post date:** [February 5, 2020, 11:22am UTC](https://discuss.elastic.co/t/date-range-not-working-no-errors-but-no-matches/217801/3 "2020-02-05T11:22:38Z")

</div>

thank you very much for the help.

---

<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:** [March 4, 2020, 11:22am UTC](https://discuss.elastic.co/t/date-range-not-working-no-errors-but-no-matches/217801/4 "2020-03-04T11:22:42Z")

</div>

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