码迷,mamicode.com
首页 > 其他好文 > 详细

来自官方的Range Query查询介绍【全英文】

时间:2017-04-01 20:31:43      阅读:499      评论:0      收藏:0      [点我收藏+]

标签:time   class   down   code   rom   end   tle   either   with   

Matches documents with fields that have terms within a certain range. The type of the Lucene query depends on the field type, for string fields, the TermRangeQuery, while for number/date fields, the query is a NumericRangeQuery. The following example returns all documents where age is between 10 and 20:

{
    "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 the section called “Date Mathedit”::

{
    "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:

{
    "range" : {
        "born" : {
            "gte": "01/01/2012",
            "lte": "2013",
            "format": "dd/MM/yyyy||yyyy"
        }
    }
}

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:

{
    "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).

 

来自官方的Range Query查询介绍【全英文】

标签:time   class   down   code   rom   end   tle   either   with   

原文地址:http://www.cnblogs.com/qijiu/p/6657365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!