Search code examples
elasticsearch

ElasticSearch Date Math find out what it's calculating


So I would like to know what now-1y is producing as a result. So is it:

  1. now - 365days
  2. now - 365.25days
  3. now with the year part subtracted, so 2014-12-23T08:46:00

I've read this documentation but can't find any more information.


Solution

  • After some testing it appears that the third proposition is correct (ie "now with the year part subtracted, so 2014-12-23T08:46:00"

    If 2 was correct the following example should have return 2 results. example1

    As 2012 is a leap year. The following example should return 0 result if 1 was correct. example2

    Note: example only worked as expected when I wrote this answer, in order to make it work for you, you have to update the date field of the indexed document.