Reputation: 767
I need to search all the documents which are older than 5 years from now. The documents contains a field called "capture_date". We can calculate how old they are from it.
{
"_index" : "liberty-429-dev",
"_type" : "_doc",
"_id" : "7ed0f73d-a979-4497-b5cf-ab6854b0fd24",
"_score" : null,
"_source" : {
"capture_date" : "2021-01-01",
"vendor_invoice_number" : ""
}
},
{
"_index" : "liberty-429-dev",
"_type" : "_doc",
"_id" : "b442a1d5-bd37-4990-94ef-0a93c9e67450",
"_score" : null,
"_source" : {
"capture_date" : "2021-01-02",
"vendor_invoice_number" : "",
}
}
These are some of the documents. Please suggest a get request query to search documents which are 5 years older than current date?
Upvotes: 0
Views: 436
Reputation: 16172
You can use range query to find the document that is 5 year older than the current date
{
"query": {
"range": {
"capture_date": {
"lt": "now-5y/y"
}
}
}
}
Upvotes: 1