Reputation: 385
In my elastic search index, I have a date field called "created" which in the following format, {'created': '2021-03-09T13:56:16.639Z' } But I need to get the documents which are created in specific date which is in format yyyy-mm-dd and I don't want the time to be compared.
I tried something like this but It not works,
res = es.search(index='blogs',body={'query': {"match_all": {}}, "aggs": {
"range": {
"date_range": {
"field": "created",
"format": "YYYY-mm-dd",
"ranges": [
{ "to": "2021-03-09" },
{ "from": "2021-03-09" }
]
}
}
}})
print(res)
How to do this?
Upvotes: 0
Views: 375
Reputation: 217444
Your date format is wrong, it must be yyyy-MM-dd
, change ti and it will work as expected
"date_range": {
"field": "created",
"format": "yyyy-MM-dd", <--- change this
"ranges": [
{ "to": "2021-03-09" },
{ "from": "2021-03-09" }
]
}
Upvotes: 1