range-query.asciidoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. [[query-dsl-range-query]]
  2. === Range Query
  3. Matches documents with fields that have terms within a certain range.
  4. The type of the Lucene query depends on the field type, for `string`
  5. fields, the `TermRangeQuery`, while for number/date fields, the query is
  6. a `NumericRangeQuery`. The following example returns all documents where
  7. `age` is between `10` and `20`:
  8. [source,js]
  9. --------------------------------------------------
  10. {
  11. "range" : {
  12. "age" : {
  13. "gte" : 10,
  14. "lte" : 20,
  15. "boost" : 2.0
  16. }
  17. }
  18. }
  19. --------------------------------------------------
  20. The `range` query accepts the following parameters:
  21. [horizontal]
  22. `gte`:: Greater-than or equal to
  23. `gt`:: Greater-than
  24. `lte`:: Less-than or equal to
  25. `lt`:: Less-than
  26. `boost`:: Sets the boost value of the query, defaults to `1.0`
  27. [float]
  28. ==== Date options
  29. When applied on `date` fields the `range` filter accepts also a `time_zone` parameter.
  30. The `time_zone` parameter will be applied to your input lower and upper bounds and will
  31. move them to UTC time based date:
  32. [source,js]
  33. --------------------------------------------------
  34. {
  35. "range" : {
  36. "born" : {
  37. "gte": "2012-01-01",
  38. "lte": "now",
  39. "time_zone": "+1:00"
  40. }
  41. }
  42. }
  43. --------------------------------------------------
  44. In the above example, `gte` will be actually moved to `2011-12-31T23:00:00` UTC date.
  45. NOTE: if you give a date with a timezone explicitly defined and use the `time_zone` parameter, `time_zone` will be
  46. ignored. For example, setting `gte` to `2012-01-01T00:00:00+01:00` with `"time_zone":"+10:00"` will still use `+01:00` time zone.
  47. When applied on `date` fields the `range` query accepts also a `format` parameter.
  48. The `format` parameter will help support another date format than the one defined in mapping:
  49. [source,js]
  50. --------------------------------------------------
  51. {
  52. "range" : {
  53. "born" : {
  54. "gte": "01/01/2012",
  55. "lte": "2013",
  56. "format": "dd/MM/yyyy||yyyy"
  57. }
  58. }
  59. }
  60. --------------------------------------------------