ElasticSearch range
Posted tingtingbai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ElasticSearch range相关的知识,希望对你有一定的参考价值。
GET _search { "query": { "range" : { "age" : { "gte" : 10, "lte" : 20, "boost" : 2.0 } } } }
The range
query accepts the following parameters:
|
Greater-than or equal to |
|
Greater-than |
|
Less-than or equal to |
|
Less-than |
|
Sets the boost value of the query, defaults to |
Ranges on date fieldsedit
When running range
queries on fields of type date
, ranges can be specified using Date Mathedit:
GET _search { "query": { "range" : { "date" : { "gte" : "now-1d/d", "lt" : "now/d" } } } }
Date math and roundingedit
When using date math to round dates to the nearest day, month, hour, etc, the rounded dates depend on whether the ends of the ranges are inclusive or exclusive.
Rounding up moves to the last millisecond of the rounding scope, and rounding down to the first millisecond of the rounding scope. For example:
|
Greater than the date rounded up: |
|
Greater than or equal to the date rounded down: |
|
Less than the date rounded down: |
|
Less than or equal to the date rounded up: |
Date format in range queriesedit
Formatted dates will be parsed using the format
specified on the date
field by default, but it can be overridden by passing the format
parameter to the range
query:
GET _search { "query": { "range" : { "born" : { "gte": "01/01/2012", "lte": "2013", "format": "dd/MM/yyyy||yyyy" } } } }
Note that if the date misses some of the year, month and day coordinates, the missing parts are filled with the start of unix time, which is January 1st, 1970. This means, that when e.g. specifying dd
as the format, a value like "gte" : 10
will translate to 1970-01-10T00:00:00.000Z
.
Time zone in range queriesedit
Dates can be converted from another timezone to UTC either by specifying the time zone in the date value itself (if the format
accepts it), or it can be specified as the time_zone
parameter:
以上是关于ElasticSearch range的主要内容,如果未能解决你的问题,请参考以下文章
Elasticsearch 使用range判断null或空字符串
ElasticSearch序列 - SpringBoot整合ES:范围查询 range