setup: - do: indices.create: index: test body: settings: number_of_replicas: 0 mappings: doc: "properties": "integer_range": "type" : "integer_range" "long_range": "type" : "long_range" "float_range": "type" : "float_range" "double_range": "type" : "double_range" "date_range": "type" : "date_range" "ip_range": "type" : "ip_range" --- "Integer range": - do: index: index: test type: doc id: 1 body: { "integer_range" : { "gte": 1, "lte": 5 } } - do: index: index: test type: doc id: 2 body: { "integer_range" : { "gte": 1, "lte": 3 } } - do: index: index: test type: doc id: 3 body: { "integer_range" : { "gte": 4, "lte": 5 } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: body: { "size" : 0, "query" : { "range" : { "integer_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } --- "Add document with null value": - skip: version: " - 6.1.99" reason: ignoring null values on range fields was introduced in 6.2.0 - do: index: index: test type: doc id: 1 body: { "integer_range" : { "gte": 1, "lte": 5 } } - do: index: index: test type: doc id: 2 body: { "integer_range" : { "gte": 1, "lte": 3 } } - do: index: index: test type: doc id: 3 body: { "integer_range" : { "gte": 4, "lte": 5 } } - do: index: index: test type: doc id: 4 body: { "integer_range" : null } - do: indices.refresh: {} - do: search: body: { "query" : { "match_all": {} } } - match: { hits.total: 4 } --- "Long range": - do: index: index: test type: doc id: 1 body: { "long_range" : { "gte": 1, "lte": 5 } } - do: index: index: test type: doc id: 2 body: { "long_range" : { "gte": 1, "lte": 3 } } - do: index: index: test type: doc id: 3 body: { "long_range" : { "gte": 4, "lte": 5 } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: body: { "size" : 0, "query" : { "range" : { "long_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } --- "Float range": - do: index: index: test type: doc id: 1 body: { "float_range" : { "gte": 1, "lte": 5 } } - do: index: index: test type: doc id: 2 body: { "float_range" : { "gte": 1, "lte": 3 } } - do: index: index: test type: doc id: 3 body: { "float_range" : { "gte": 4, "lte": 5 } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: body: { "size" : 0, "query" : { "range" : { "float_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } --- "Double range": - do: index: index: test type: doc id: 1 body: { "double_range" : { "gte": 1, "lte": 5 } } - do: index: index: test type: doc id: 2 body: { "double_range" : { "gte": 1, "lte": 3 } } - do: index: index: test type: doc id: 3 body: { "double_range" : { "gte": 4, "lte": 5 } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4 } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: body: { "size" : 0, "query" : { "range" : { "double_range" : { "gte": 3, "lte" : 4, "relation": "within" } } } } - match: { hits.total: 0 } --- "IP range": - do: index: index: test type: doc id: 1 body: { "ip_range" : { "gte": "192.168.0.1", "lte": "192.168.0.5" } } - do: index: index: test type: doc id: 2 body: { "ip_range" : { "gte": "192.168.0.1", "lte": "192.168.0.3" } } - do: index: index: test type: doc id: 3 body: { "ip_range" : { "gte": "192.168.0.4", "lte": "192.168.0.5" } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: body: { "size" : 0, "query" : { "range" : { "ip_range" : { "gte": "192.168.0.3", "lte" : "192.168.0.4", "relation": "within" } } } } - match: { hits.total: 0 } --- "Date range": - do: index: index: test type: doc id: 1 body: { "date_range" : { "gte": "2017-09-01", "lte": "2017-09-05" } } - do: index: index: test type: doc id: 2 body: { "date_range" : { "gte": "2017-09-01", "lte": "2017-09-03" } } - do: index: index: test type: doc id: 3 body: { "date_range" : { "gte": "2017-09-04", "lte": "2017-09-05" } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "intersects" } } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "contains" } } } } - match: { hits.total: 1 } - do: search: body: { "size" : 0, "query" : { "range" : { "date_range" : { "gte": "2017-09-03", "lte" : "2017-09-04", "relation": "within" } } } } - match: { hits.total: 0 } --- "Query on range fields in query_string": - skip: version: " - 6.0.99" reason: "Support for range field in query_string was introduced in 6.1 (#26552)" - do: index: index: test type: doc id: 1 body: { "integer_range" : { "gte": 1, "lte": 5 }, "long_range" : { "gte": 1, "lte": 5 }, "float_range" : { "gte": 1, "lte": 5 }, "double_range" : { "gte": 1, "lte": 5 }, "ip_range" : { "gte": "192.168.0.1", "lte": "192.168.0.5" }, "date_range" : { "gte": "2017-09-01", "lte": "2017-09-05" } } - do: index: index: test type: doc id: 2 body: { "integer_range" : { "gte": 1, "lte": 3 }, "long_range" : { "gte": 1, "lte": 3 }, "float_range" : { "gte": 1, "lte": 3 }, "double_range" : { "gte": 1, "lte":3 }, "ip_range" : { "gte": "192.168.0.1", "lte": "192.168.0.3" }, "date_range" : { "gte": "2017-09-01", "lte": "2017-09-03" } } - do: index: index: test type: doc id: 3 body: { "integer_range" : { "gte": 4, "lte": 5 }, "long_range" : { "gte": 4, "lte": 5 }, "float_range" : { "gte": 4, "lte": 5 }, "double_range" : { "gte": 4, "lte":5 }, "ip_range" : { "gte": "192.168.0.4", "lte": "192.168.0.5" }, "date_range" : { "gte": "2017-09-04", "lte": "2017-09-05" } } - do: indices.refresh: {} - do: search: body: { "size" : 0, "query" : { "query_string" : { "query" : "integer_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "query_string" : { "query" : "long_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "query_string" : { "query" : "float_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "query_string" : { "query" : "double_range:[3 TO 4]" } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "query_string" : { "query" : "ip_range:[192.168.0.3 TO 192.168.0.4]" } } } - match: { hits.total: 3 } - do: search: body: { "size" : 0, "query" : { "query_string" : { "query" : "date_range:[2017-09-03 TO 2017-09-04]" } } } - match: { hits.total: 3 }