diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/40_range.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/40_range.yml index 57b61b242d8c8..afe66e4340d3b 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/40_range.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/40_range.yml @@ -7,420 +7,205 @@ setup: number_of_replicas: 0 mappings: properties: - ip: - type: ip double: type: double - date: - type: date - format: epoch_second + long: + type: long - do: cluster.health: - wait_for_status: green - ---- -"Double range": - - do: - index: - index: test - id: 1 - body: { "double" : 42 } - - - do: - index: - index: test - id: 2 - body: { "double" : 100 } + wait_for_status: yellow - do: - index: + bulk: index: test - id: 3 - body: { "double" : 50 } - - - do: - indices.refresh: {} + refresh: true + body: + - {"index": {}} + - { "double" : 42.1, "long": 25 } + - {"index": {}} + - { "double" : 100.7, "long": 80 } + - {"index": {}} + - { "double" : 50.5, "long": 75} +# For testing missing values + - {"index": {}} + - {} +--- +"Double range": - do: search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "double_range" : { "range" : { "field" : "double", "ranges": [ { "to": 50 }, { "from": 50, "to": 150 }, { "from": 150 } ] } } } } - - - match: { hits.total: 3 } - + body: + size: 0 + aggs: + double_range: + range: + field: "double" + ranges: + - + to: 50 + - + from: 50 + to: 150 + - + from: 150 + + - match: { hits.total.relation: "eq" } + - match: { hits.total.value: 4 } - length: { aggregations.double_range.buckets: 3 } - - match: { aggregations.double_range.buckets.0.key: "*-50.0" } - - is_false: aggregations.double_range.buckets.0.from - - match: { aggregations.double_range.buckets.0.to: 50.0 } - - match: { aggregations.double_range.buckets.0.doc_count: 1 } - - match: { aggregations.double_range.buckets.1.key: "50.0-150.0" } - - match: { aggregations.double_range.buckets.1.from: 50.0 } - - match: { aggregations.double_range.buckets.1.to: 150.0 } - - match: { aggregations.double_range.buckets.1.doc_count: 2 } - - match: { aggregations.double_range.buckets.2.key: "150.0-*" } - - match: { aggregations.double_range.buckets.2.from: 150.0 } - - is_false: aggregations.double_range.buckets.2.to - - match: { aggregations.double_range.buckets.2.doc_count: 0 } +--- +"Double range with missing value": - do: search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "double_range" : { "range" : { "field" : "double", "ranges": [ { "from": null, "to": 50 }, { "from": 50, "to": 150 }, { "from": 150, "to": null } ] } } } } - - - match: { hits.total: 3 } - + body: + size: 0 + aggs: + double_range: + range: + field: "double" + missing: 1000 + ranges: + - + to: 50 + - + from: 50 + to: 150 + - + from: 150 + + - match: { hits.total.relation: "eq" } + - match: { hits.total.value: 4 } - length: { aggregations.double_range.buckets: 3 } - - match: { aggregations.double_range.buckets.0.key: "*-50.0" } - - is_false: aggregations.double_range.buckets.0.from - - match: { aggregations.double_range.buckets.0.to: 50.0 } - - match: { aggregations.double_range.buckets.0.doc_count: 1 } - - match: { aggregations.double_range.buckets.1.key: "50.0-150.0" } - - match: { aggregations.double_range.buckets.1.from: 50.0 } - - match: { aggregations.double_range.buckets.1.to: 150.0 } - - match: { aggregations.double_range.buckets.1.doc_count: 2 } - - match: { aggregations.double_range.buckets.2.key: "150.0-*" } - - match: { aggregations.double_range.buckets.2.from: 150.0 } - - is_false: aggregations.double_range.buckets.2.to - - - match: { aggregations.double_range.buckets.2.doc_count: 0 } - ---- -"IP range": - - do: - index: - index: test - id: 1 - body: { "ip" : "::1" } - - - do: - index: - index: test - id: 2 - body: { "ip" : "192.168.0.1" } - - - do: - index: - index: test - id: 3 - body: { "ip" : "192.168.0.7" } - - - do: - indices.refresh: {} - - - do: - search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "to": "192.168.0.0" }, { "from": "192.168.0.0", "to": "192.169.0.0" }, { "from": "192.169.0.0" } ] } } } } - - - match: { hits.total: 3 } - - - length: { aggregations.ip_range.buckets: 3 } - - - is_false: aggregations.ip_range.buckets.0.from - - - match: { aggregations.ip_range.buckets.0.to: "192.168.0.0" } - - - match: { aggregations.ip_range.buckets.0.doc_count: 1 } - - - match: { aggregations.ip_range.buckets.1.from: "192.168.0.0" } - - - match: { aggregations.ip_range.buckets.1.to: "192.169.0.0" } - - - match: { aggregations.ip_range.buckets.1.doc_count: 2 } - - - match: { aggregations.ip_range.buckets.2.from: "192.169.0.0" } - - - is_false: aggregations.ip_range.buckets.2.to - - - match: { aggregations.ip_range.buckets.2.doc_count: 0 } - - - do: - search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "from": null, "to": "192.168.0.0" }, { "from": "192.168.0.0", "to": "192.169.0.0" }, { "from": "192.169.0.0", "to": null } ] } } } } - - - match: { hits.total: 3 } - - - length: { aggregations.ip_range.buckets: 3 } - - - is_false: aggregations.ip_range.buckets.0.from - - - match: { aggregations.ip_range.buckets.0.to: "192.168.0.0" } - - - match: { aggregations.ip_range.buckets.0.doc_count: 1 } - - - match: { aggregations.ip_range.buckets.1.from: "192.168.0.0" } - - - match: { aggregations.ip_range.buckets.1.to: "192.169.0.0" } - - - match: { aggregations.ip_range.buckets.1.doc_count: 2 } - - - match: { aggregations.ip_range.buckets.2.from: "192.169.0.0" } - - - is_false: aggregations.ip_range.buckets.2.to - - - match: { aggregations.ip_range.buckets.2.doc_count: 0 } - - - do: - search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "mask": "::/24" }, { "mask": "192.168.0.0/16" } ] } } } } - - - match: { hits.total: 3 } - - - length: { aggregations.ip_range.buckets: 2 } - - - match: { aggregations.ip_range.buckets.0.key: "::/24" } - - - match: { aggregations.ip_range.buckets.0.to: "0:100::" } - - - match: { aggregations.ip_range.buckets.0.doc_count: 3 } - - - match: { aggregations.ip_range.buckets.1.key: "192.168.0.0/16" } - - - match: { aggregations.ip_range.buckets.1.from: "192.168.0.0" } - - - match: { aggregations.ip_range.buckets.1.to: "192.169.0.0" } - - - match: { aggregations.ip_range.buckets.1.doc_count: 2 } + - match: { aggregations.double_range.buckets.2.doc_count: 1 } --- -"IP Range Key Generation": - +"Null to and from": - do: search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "ip_range" : { "ip_range" : { "field" : "ip", "ranges": [ { "to": "192.168.0.0" }, { "from": "192.168.0.0", "to": "192.169.0.0" }, { "from": "192.169.0.0" } ] } } } } - - - length: { aggregations.ip_range.buckets: 3 } - - match: { aggregations.ip_range.buckets.0.key: "*-192.168.0.0" } - - match: { aggregations.ip_range.buckets.1.key: "192.168.0.0-192.169.0.0" } - - match: { aggregations.ip_range.buckets.2.key: "192.169.0.0-*" } - ---- -"IP Range avg_bucket": - - skip: - version: " - 7.7.99" - reason: Fixed in 7.8.0 - - do: - bulk: - refresh: true - index: test - body: - - '{"index": {}}' - - '{"ip": "::1", "v": 1}' - - '{"index": {}}' - - '{"ip": "192.168.0.1", "v": 2}' - - '{"index": {}}' - - '{"ip": "192.168.0.7", "v": 3}' - - - do: - search: - index: test body: size: 0 aggs: - range: - ip_range: - field: ip + double_range: + range: + field: "double" ranges: - - to: 192.168.0.0 - - from: 192.168.0.0 - to: 192.169.0.0 - - from: 192.169.0.0 - aggs: - v: - sum: - field: v - range_avg_v: - avg_bucket: - buckets_path: range.v - - - match: { hits.total.value: 3 } - - length: { aggregations.range.buckets: 3 } - - match: { aggregations.range.buckets.0.key: "*-192.168.0.0" } - - match: { aggregations.range.buckets.0.doc_count: 1 } - - match: { aggregations.range.buckets.0.v.value: 1 } - - match: { aggregations.range.buckets.1.key: "192.168.0.0-192.169.0.0" } - - match: { aggregations.range.buckets.1.doc_count: 2 } - - match: { aggregations.range.buckets.1.v.value: 5 } - - match: { aggregations.range.buckets.2.key: "192.169.0.0-*" } - - match: { aggregations.range.buckets.2.doc_count: 0 } - - match: { aggregations.range.buckets.2.v.value: 0 } - - match: { aggregations.range_avg_v.value: 3 } - ---- -"Date range": - - do: - index: - index: test - id: 1 - body: { "date" : 1000 } - - - do: - index: - index: test - id: 2 - body: { "date" : 2000 } - - - do: - index: - index: test - id: 3 - body: { "date" : 3000 } - - - do: - indices.refresh: {} - - - do: - search: - rest_total_hits_as_int: true - body: { "size" : 0, "aggs" : { "date_range" : { "date_range" : { "field" : "date", "ranges": [ { "from" : 1000, "to": 3000 }, { "from": 3000, "to": 4000 } ] } } } } - - - match: { hits.total: 3 } - - - length: { aggregations.date_range.buckets: 2 } - - - match: { aggregations.date_range.buckets.0.doc_count: 2 } - - match: { aggregations.date_range.buckets.0.key: "1000-3000" } - - match: { aggregations.date_range.buckets.0.from: 1000000 } - - match: { aggregations.date_range.buckets.0.to: 3000000 } - - - match: { aggregations.date_range.buckets.1.doc_count: 1 } - - match: { aggregations.date_range.buckets.1.key: "3000-4000" } - - match: { aggregations.date_range.buckets.1.from: 3000000 } - - match: { aggregations.date_range.buckets.1.to: 4000000 } + - + from: null + to: 50 + - + from: 50 + to: 150 + - + from: 150 + to: null + + - match: { hits.total.relation: "eq" } + - match: { hits.total.value: 4 } + - length: { aggregations.double_range.buckets: 3 } + - match: { aggregations.double_range.buckets.0.key: "*-50.0" } + - is_false: aggregations.double_range.buckets.0.from + - match: { aggregations.double_range.buckets.0.to: 50.0 } + - match: { aggregations.double_range.buckets.0.doc_count: 1 } + - match: { aggregations.double_range.buckets.1.key: "50.0-150.0" } + - match: { aggregations.double_range.buckets.1.from: 50.0 } + - match: { aggregations.double_range.buckets.1.to: 150.0 } + - match: { aggregations.double_range.buckets.1.doc_count: 2 } + - match: { aggregations.double_range.buckets.2.key: "150.0-*" } + - match: { aggregations.double_range.buckets.2.from: 150.0 } + - is_false: aggregations.double_range.buckets.2.to + - match: { aggregations.double_range.buckets.2.doc_count: 0 } --- -"Date Range Missing": - - do: - index: - index: test - id: 1 - body: { "date" : "28800000000" } - - - do: - index: - index: test - id: 2 - body: { "date" : "315561600000" } - - - do: - index: - index: test - id: 3 - body: { "date" : "631180800000" } - - - do: - index: - index: test - id: 4 - body: { "date" : "10000" } - - - do: - index: - index: test - id: 5 - body: { "ip" : "192.168.0.1" } - - - do: - indices.refresh: {} - +"Range agg on long field": - do: search: - rest_total_hits_as_int: true body: + size: 0 aggs: - age_groups: - date_range: - field: date - missing: "0" + long_range: + range: + field: "long" ranges: - - key: Generation Y - from: '315561600000' - to: '946713600000' - - key: Generation X - from: "200000" - to: '315561600000' - - key: Other - to: "200000" - - - match: { hits.total: 5 } - - - length: { aggregations.age_groups.buckets: 3 } - - - match: { aggregations.age_groups.buckets.0.key: "Other" } - - - match: { aggregations.age_groups.buckets.0.doc_count: 2 } - - - match: { aggregations.age_groups.buckets.1.key: "Generation X" } - - - match: { aggregations.age_groups.buckets.1.doc_count: 1 } - - - match: { aggregations.age_groups.buckets.2.key: "Generation Y" } - - - match: { aggregations.age_groups.buckets.2.doc_count: 2 } - + - + to: 50 + - + from: 50 + to: 150 + - + from: 150 + + - match: { hits.total.relation: "eq" } + - match: { hits.total.value: 4 } + - length: { aggregations.long_range.buckets: 3 } + - match: { aggregations.long_range.buckets.0.key: "*-50.0" } + - is_false: aggregations.long_range.buckets.0.from + - match: { aggregations.long_range.buckets.0.to: 50 } + - match: { aggregations.long_range.buckets.0.doc_count: 1 } + - match: { aggregations.long_range.buckets.1.key: "50.0-150.0" } + - match: { aggregations.long_range.buckets.1.from: 50 } + - match: { aggregations.long_range.buckets.1.to: 150 } + - match: { aggregations.long_range.buckets.1.doc_count: 2 } + - match: { aggregations.long_range.buckets.2.key: "150.0-*" } + - match: { aggregations.long_range.buckets.2.from: 150 } + - is_false: aggregations.long_range.buckets.2.to + - match: { aggregations.long_range.buckets.2.doc_count: 0 } --- -"Date range unmapped with children": - - skip: - version: " - 7.9.99" - reason: Fixed in 7.10.0 - - - do: - indices.create: - index: test_a_unmapped - body: - settings: - number_of_shards: 1 - number_of_replicas: 0 +"Double range default keyed response": - do: search: - index: test_a_unmapped body: size: 0 - query: - terms: - animal: [] aggs: - date_range: - date_range: - field: date + double_range: + range: + field: "double" + keyed: true ranges: - - from: 2020-01-01T00:00:00Z - aggs: - sounds: - cardinality: - field: sound.keyword - - - match: { hits.total.value: 0 } - - length: { aggregations.date_range.buckets: 1 } - - match: { aggregations.date_range.buckets.0.doc_count: 0 } - - match: { aggregations.date_range.buckets.0.key: "2020-01-01T00:00:00.000Z-*" } - - is_false: aggregations.date_range.buckets.0.to - - match: { aggregations.date_range.buckets.0.sounds.value: 0 } + - + key: "first" + to: 50 + - + key: "another" + from: 50 + to: 150 + - + key: "last" + from: 150 + + - match: { hits.total.relation: "eq" } + - match: { hits.total.value: 4 } + - length: { aggregations.double_range.buckets: 3 } + - is_false: aggregations.double_range.buckets.first.from + - match: { aggregations.double_range.buckets.first.to: 50.0 } + - match: { aggregations.double_range.buckets.first.doc_count: 1 } + - match: { aggregations.double_range.buckets.another.from: 50.0 } + - match: { aggregations.double_range.buckets.another.to: 150.0 } + - match: { aggregations.double_range.buckets.another.doc_count: 2 } + - match: { aggregations.double_range.buckets.last.from: 150.0 } + - is_false: aggregations.double_range.buckets.last.to + - match: { aggregations.double_range.buckets.last.doc_count: 0 } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/41_date_range.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/41_date_range.yml new file mode 100644 index 0000000000000..e1160520ac3e7 --- /dev/null +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/41_date_range.yml @@ -0,0 +1,169 @@ +setup: + - do: + indices.create: + index: old_test + body: + settings: + number_of_replicas: 0 + mappings: + properties: + date: + type: date + format: epoch_second + + - do: + indices.create: + index: test + body: + settings: + number_of_replicas: 0 + mappings: + properties: + date: + type: date + format: epoch_second + + - do: + cluster.health: + wait_for_status: yellow + +# March 8th 2020 was the start of daylight savings time that year + - do: + bulk: + index: test + refresh: true + body: + - {"index": {}} + - { "date" : "2020-03-08T06:15:00Z" } + - {"index": {}} + - { "date" : "2020-03-08T07:15:00Z" } + +--- +"Date range": + - do: + bulk: + index: old_test + refresh: true + body: + - {"index": {}} + - { "date" : 1000 } + - {"index": {}} + - { "date" : 2000 } + - {"index": {}} + - { "date" : 3000 } + + - do: + search: + body: + size: 0 + aggs: + date_range: + date_range: + field: "date" + ranges: + - + from: 1000 + to: 3000 + - + from: 3000 + to: 4000 + + + - match: { hits.total.value: 3 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.date_range.buckets: 2 } + - match: { aggregations.date_range.buckets.0.doc_count: 2 } + - match: { aggregations.date_range.buckets.0.key: "1000-3000" } + - match: { aggregations.date_range.buckets.0.from: 1000000 } + - match: { aggregations.date_range.buckets.0.to: 3000000 } + + - match: { aggregations.date_range.buckets.1.doc_count: 1 } + - match: { aggregations.date_range.buckets.1.key: "3000-4000" } + - match: { aggregations.date_range.buckets.1.from: 3000000 } + - match: { aggregations.date_range.buckets.1.to: 4000000 } + +--- +"Date Range Missing": + - do: + bulk: + index: old_test + refresh: true + body: + - {"index": {}} + - { "date" : "28800000000" } + - {"index": {}} + - { "date" : "315561600000" } + - {"index": {}} + - { "date" : "631180800000" } + - {"index": {}} + - { "date" : "10000" } + - {"index": {}} + - { "ip" : "192.168.0.1" } + + - do: + search: + body: + aggs: + age_groups: + date_range: + field: date + missing: "0" + ranges: + - key: Generation Y + from: '315561600000' + to: '946713600000' + - key: Generation X + from: "200000" + to: '315561600000' + - key: Other + to: "200000" + + - match: { hits.total.value: 5 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.age_groups.buckets: 3 } + - match: { aggregations.age_groups.buckets.0.key: "Other" } + - match: { aggregations.age_groups.buckets.0.doc_count: 2 } + - match: { aggregations.age_groups.buckets.1.key: "Generation X" } + - match: { aggregations.age_groups.buckets.1.doc_count: 1 } + - match: { aggregations.age_groups.buckets.2.key: "Generation Y" } + - match: { aggregations.age_groups.buckets.2.doc_count: 2 } + + +--- +"Date range unmapped with children": + - skip: + version: " - 7.9.99" + reason: Fixed in 7.10.0 + + - do: + indices.create: + index: test_a_unmapped + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + - do: + search: + index: test_a_unmapped + body: + size: 0 + query: + terms: + animal: [] + aggs: + date_range: + date_range: + field: date + ranges: + - from: 2020-01-01T00:00:00Z + aggs: + sounds: + cardinality: + field: sound.keyword + + - match: { hits.total.value: 0 } + - length: { aggregations.date_range.buckets: 1 } + - match: { aggregations.date_range.buckets.0.doc_count: 0 } + - match: { aggregations.date_range.buckets.0.key: "2020-01-01T00:00:00.000Z-*" } + - is_false: aggregations.date_range.buckets.0.to + - match: { aggregations.date_range.buckets.0.sounds.value: 0 } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/42_ip_range.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/42_ip_range.yml new file mode 100644 index 0000000000000..461732a0d461d --- /dev/null +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/42_ip_range.yml @@ -0,0 +1,193 @@ +setup: + - do: + indices.create: + index: test + body: + settings: + number_of_replicas: 0 + mappings: + properties: + ip: + type: ip + + - do: + cluster.health: + wait_for_status: yellow + +--- +"IP range": + - do: + bulk: + index: test + refresh: true + body: + - {"index": {}} + - { "ip" : "::1" } + - {"index": {}} + - { "ip" : "192.168.0.1" } + - {"index": {}} + - { "ip" : "192.168.0.7" } + + - do: + search: + body: + size: 0 + aggs: + ip_range: + ip_range: + field: "ip" + ranges: + - + to: "192.168.0.0" + - + from: "192.168.0.0" + to: "192.169.0.0" + - + from: "192.169.0.0" + + - match: { hits.total.value: 3 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.ip_range.buckets: 3 } + - is_false: aggregations.ip_range.buckets.0.from + - match: { aggregations.ip_range.buckets.0.to: "192.168.0.0" } + - match: { aggregations.ip_range.buckets.0.doc_count: 1 } + - match: { aggregations.ip_range.buckets.1.from: "192.168.0.0" } + - match: { aggregations.ip_range.buckets.1.to: "192.169.0.0" } + - match: { aggregations.ip_range.buckets.1.doc_count: 2 } + - match: { aggregations.ip_range.buckets.2.from: "192.169.0.0" } + - is_false: aggregations.ip_range.buckets.2.to + - match: { aggregations.ip_range.buckets.2.doc_count: 0 } + + - do: + search: + body: + size: 0 + aggs: + ip_range: + ip_range: + field: "ip" + ranges: + - + from: null + to: "192.168.0.0" + - + from: "192.168.0.0" + to: "192.169.0.0" + - + from: "192.169.0.0" + to: null + + - match: { hits.total.value: 3 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.ip_range.buckets: 3 } + - is_false: aggregations.ip_range.buckets.0.from + - match: { aggregations.ip_range.buckets.0.to: "192.168.0.0" } + - match: { aggregations.ip_range.buckets.0.doc_count: 1 } + - match: { aggregations.ip_range.buckets.1.from: "192.168.0.0" } + - match: { aggregations.ip_range.buckets.1.to: "192.169.0.0" } + - match: { aggregations.ip_range.buckets.1.doc_count: 2 } + - match: { aggregations.ip_range.buckets.2.from: "192.169.0.0" } + - is_false: aggregations.ip_range.buckets.2.to + - match: { aggregations.ip_range.buckets.2.doc_count: 0 } + + - do: + search: + body: + size: 0 + aggs: + ip_range: + ip_range: + field: "ip" + ranges: + - + mask: "::/24" + - + mask: "192.168.0.0/16" + + - match: { hits.total.value: 3 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.ip_range.buckets: 2 } + - match: { aggregations.ip_range.buckets.0.key: "::/24" } + - match: { aggregations.ip_range.buckets.0.to: "0:100::" } + - match: { aggregations.ip_range.buckets.0.doc_count: 3 } + - match: { aggregations.ip_range.buckets.1.key: "192.168.0.0/16" } + - match: { aggregations.ip_range.buckets.1.from: "192.168.0.0" } + - match: { aggregations.ip_range.buckets.1.to: "192.169.0.0" } + - match: { aggregations.ip_range.buckets.1.doc_count: 2 } + +--- +"IP Range Key Generation": + + - do: + search: + body: + size: 0 + aggs: + ip_range: + ip_range: + field: "ip" + ranges: + - + to: "192.168.0.0" + - + from: "192.168.0.0" + to: "192.169.0.0" + - + from: "192.169.0.0" + + - length: { aggregations.ip_range.buckets: 3 } + - match: { aggregations.ip_range.buckets.0.key: "*-192.168.0.0" } + - match: { aggregations.ip_range.buckets.1.key: "192.168.0.0-192.169.0.0" } + - match: { aggregations.ip_range.buckets.2.key: "192.169.0.0-*" } + +--- +"IP Range avg_bucket": + - skip: + version: " - 7.7.99" + reason: Fixed in 7.8.0 + - do: + bulk: + refresh: true + index: test + body: + - '{"index": {}}' + - '{"ip": "::1", "v": 1}' + - '{"index": {}}' + - '{"ip": "192.168.0.1", "v": 2}' + - '{"index": {}}' + - '{"ip": "192.168.0.7", "v": 3}' + + - do: + search: + index: test + body: + size: 0 + aggs: + range: + ip_range: + field: ip + ranges: + - to: 192.168.0.0 + - from: 192.168.0.0 + to: 192.169.0.0 + - from: 192.169.0.0 + aggs: + v: + sum: + field: v + range_avg_v: + avg_bucket: + buckets_path: range.v + + - match: { hits.total.value: 3 } + - length: { aggregations.range.buckets: 3 } + - match: { aggregations.range.buckets.0.key: "*-192.168.0.0" } + - match: { aggregations.range.buckets.0.doc_count: 1 } + - match: { aggregations.range.buckets.0.v.value: 1 } + - match: { aggregations.range.buckets.1.key: "192.168.0.0-192.169.0.0" } + - match: { aggregations.range.buckets.1.doc_count: 2 } + - match: { aggregations.range.buckets.1.v.value: 5 } + - match: { aggregations.range.buckets.2.key: "192.169.0.0-*" } + - match: { aggregations.range.buckets.2.doc_count: 0 } + - match: { aggregations.range.buckets.2.v.value: 0 } + - match: { aggregations.range_avg_v.value: 3 }