Search documents by date range

Searching for information is an essential requirement which is needed for every customer project. For example, if you want to search for all product with brand A in your store or how many products which have been sold from date D1 to date D2, etc. In this tutorial, we will find out how to get the documents by date range supported in Services

Format

Standard format date for this kind of filter search is yyyy-MM-dd.

Format to get the data filter by rage is as follows.

filter=Field:[FROM_DATE TO TO_DATE]

The range query includes FROM_DATE and TO_DATE into the result set. Please note that this feature cannot work in the scenario where a data model is not provided (all documents search scenario).

Example

If you want to search for all products sold from May 1, 2017 to May 29, 2017, you can create a filter

filter=Product.SoldDate:[2017-05-01 TO 2017-05-29]

Under the hood, the dates are turned into milliseconds since January 1, 1970, 00:00:00. Negative ranges are also possible in the same way filter search uses them.

Please be aware that this kind of range filter search can be applied for number, time with format HH:mm:ss and date-time with format yyyy-MM-dd'T'HH:mm:ss.

Hopefully after reading this, you would know how to do a filter search for either date, time, date-time or number range.