# Search by Date
The application allows you to perform queries by date in any field with a date type. In this type of fields you can search by time frames based on a year, month, week, day, hour, minute or second.
To search for results within a given date range, you can use the symbols >
(after), =
(equal to), and <
(before).
A search can be made by year (y
), month (M
), week (w
), day (d
), hour (h
or H
), minute (m
), or second (s
). To add one hour, write +1h
inside the search box. To subtract one day, write -1d
.
TIP
If you want to try more real-world examples of this type of queries, consult this list.
In addition to the current date (now
), we can also use an absolute reference date that can be specific as 2010-01-01
. In this field, we must use the ||
symbol after the date: 2010-01-01||
. Then we can optionally use one or more mathematical expressions, for example, -1y
as in 2010-01-01||-1y
, +2M
, -4w
, etc.
WARNING
Please be aware that, in all date-based search queries that include one or more special characters, you must insert an inverted backslash - \
- before each.
An alternative way of using a specific reference date in time consists in using structured search . Using structured search for searching for a range of dates can be done as long as the field used for search is of a date type. In this case, the user will be asked to select a specific date in the dd-mm-yyyy
format from a calendar that will automatically appear once the user clicks with the mouse button inside the search field.
Finally, you can also use the following expression: [start_date TO end_date]
as in [2022-11-10 TO 2022-11-11]
. Click on this link (opens new window) to try it yourself or watch the brief video included below:
ElasticSearch's (the search engine of the CoB platform) range syntax also supports (opens new window) replacing a specific date in time for an asterisk - * - as in [2022-11-10 TO *]
(try it here (opens new window)) or [* TO 2022-11-10] (try it here (opens new window)). The inclusion of the asterisk implies that we want to find results for all records starting from the first ever created up to the given end date or starting from the given start date up to the last record created.
If we want to get all records whose time range corresponds to the current year/month/day/etc. we just need to insert a sidebar - /
- and escape it - \/
-, followed by the character corresponding to the desired time range. This operation can be placed before or after the mathematical expression. The records obtained by now\/d-1h
will thus be in principle equivalent to those obtained with now-1h\/d
*.
Below you will find a more detailed explanation of how date-based search queries work.
# Some examples taken (opens new window) from ElasticSearch's documentation:
Assuming now is 2001-01-01 12:00:00:000
, some examples are:
Example | Explanation |
---|---|
now+1h | now plus one hour. Resolves to: 2001-01-01 13:00:00:000 |
now-1h | now minus one hour. Resolves to: 2001-01-01 11:00:00:000 |
now-1h\/d | now minus one hour, recorded since UTC 00:00 of the same day. Resolves to: 2001-01-01 00:00:00:000 |
2001-02-01\|\|+1M\/d | 2001-02-01 in milliseconds plus one month. Resolves to: 2001-03-01 00:00:00 |
# Video: additional example
Steps:
- In this specific case, and based on the data we have, we will conduct research with dates before the current moment in 5, 6 and 7 years.
- For instance, if we need all the instances related to data recorded up to 5 years before the present date, we type
*year*
- the name of the field - followed by.date
to indicate that it is a field that refers to a date, and finally:<now-5y
. Here is the full query:year.date:<now-5y
. The last part of the search query refers to a mathematical expression. This expression means that to the current date we subtract two years (-5y
). - If we wanted to search for any results scheduled for the next two years, we would instead need to add the actual date (
now
) to2y
:now+2y
.
* That is, unless daylight saving time is in effect at the current time of year.