ElasticSearch range

GET _search
{
    "query": {
        "range" : {
            "age" : {
                "gte" : 10,
                "lte" : 20,
                "boost" : 2.0
            }
        }
    }
}

The range query accepts the following parameters:

gte

Greater-than or equal to

gt

Greater-than

lte

Less-than or equal to

lt

Less-than

boost

Sets the boost value of the query, defaults to 1.0

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:

gt

Greater than the date rounded up: 2014-11-18||/M becomes 2014-11-30T23:59:59.999, ie excluding the entire month.

gte

Greater than or equal to the date rounded down: 2014-11-18||/M becomes 2014-11-01, ie including the entire month.

lt

Less than the date rounded down: 2014-11-18||/M becomes 2014-11-01, ie excluding the entire month.

lte

Less than or equal to the date rounded up: 2014-11-18||/M becomes 2014-11-30T23:59:59.999, ie including the entire month.

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 ddas 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:

GET _search
{
    "query": {
        "range" : {
            "timestamp" : {
                "gte": "2015-01-01 00:00:00", 
                "lte": "now", 
                "time_zone": "+01:00"
            }
        }
    }
}

This date will be converted to 2014-12-31T23:00:00 UTC.

now is not affected by the time_zone parameter (dates must be stored as UTC).

转载于:https://www.cnblogs.com/tingtingbai/p/9717573.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值