Elasticsearch Term Level Queries – Range Query

Range Query will match documents with fields that have terms within a certain range.

I. Number in Range Query

For example, returns all documents where age is between 25 and 30:

With:
gte: Greater-than or equal to
gt: Greater-than
lte: Less-than or equal to
lt: Less-than
boost: boost value of the query, defaults to 1.0

This is the Response:

II. Date Format in Range Query

By default, Dates will be parsed using the format specified on the date field , but it can be overridden by passing the format parameter to the range query:

The Response:

We can find more formats at: Built-in Date Formats

III. Date Math

We can specify ranges using Date Math:

The expression starts with an anchor date, which can either be now, or a date string ending with ||.
This anchor date can optionally be followed by one or more maths expressions:
+10h – add ten hours
-10d – subtract ten days
/d – round down to the nearest day

The supported units are:
y – years
M – months
w – weeks
d – days
h – hours
H – hours
m – minutes
s – seconds

For examples:
now+1h: The current time + one hour (ms).
now+1h+1m: The current time + one hour + one minute (ms).
now+1h/d: The current time + one hour, rounded down to the nearest day.
2017-06-08||+1M/d: 2017-06-08 + one month, rounded down to the nearest day.

By JavaSampleApproach | November 4, 2017.

Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*