From 5b2d2434d4e070dcbfbec072a00e7d945034bf10 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Wed, 23 Mar 2022 12:50:48 +0100 Subject: [PATCH 01/12] fix: ordering terms aggregation on top metrics null values If top metrics buckets are never collected (i.e. a filter never passing data to a top metrics aggregator) ordering results in an index out of bounds exception. THis is because the data array expected to include data is actually empty. Here we use the special Double.NaN value to report missing data to sort on for the top metrics metric field. This results in the comparator ordering data using another comparator (the default '_key' comprator). --- .../test/search.aggregation/20_terms.yml | 598 +++++++++++++++++ .../22_terms_disable_opt.yml | 568 ++++++++++++++++ .../500_terms_order_by_top_metrics.yml | 615 ++++++++++++++++++ .../topmetrics/TopMetricsAggregator.java | 5 +- 4 files changed, 1785 insertions(+), 1 deletion(-) create mode 100644 rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml index 119c5c8234441..0bc5ea2cf765d 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml @@ -34,6 +34,67 @@ setup: number: type: double + - do: + indices.create: + index: test_order_by_top_metrics + body: + settings: + number_of_replicas: 0 + mappings: + properties: + name: + type: keyword + birth_date: + type: date + null_date: + type: date + order_date: + type: date + score: + type: integer + version: + type: integer + price: + type: double + + - do: + bulk: + index: test_order_by_top_metrics + refresh: true + body: + - { "index": { } } + - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } + - { "index": { } } + - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } + - { "index": { } } + - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } + - { "index": { } } + - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } + - { "index": { } } + - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } + - do: cluster.health: wait_for_status: green @@ -63,6 +124,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str" } } } } @@ -107,6 +169,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip" } } } } @@ -129,6 +192,7 @@ setup: - do: search: rest_total_hits_as_int: true + index: test_1 body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "include" : [ "127.0.0.1" ] } } } } - match: { hits.total: 3 } @@ -140,6 +204,7 @@ setup: - do: search: rest_total_hits_as_int: true + index: test_1 body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "exclude" : [ "127.0.0.1" ] } } } } - match: { hits.total: 3 } @@ -182,6 +247,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "boolean_terms" : { "terms" : { "field" : "boolean" } } } } @@ -226,6 +292,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "integer_terms" : { "terms" : { "field" : "integer" } } } } @@ -270,6 +337,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_terms" : { "terms" : { "field" : "double" } } } } @@ -314,6 +382,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date" } } } } @@ -335,6 +404,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date", "include" : [ "2016-05-03" ] } } } } @@ -348,6 +418,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date", "exclude" : [ "2016-05-03" ] } } } } @@ -385,6 +456,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "include" : {"partition": 0, "num_partitions": 2 } } } } } @@ -400,6 +472,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "include" : {"partition": 1, "num_partitions": 2 } } } } } @@ -439,6 +512,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "integer", "include" : {"partition": 0, "num_partitions": 2 } } } } } @@ -452,6 +526,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "integer", "include" : {"partition": 1, "num_partitions": 2 } } } } } @@ -477,6 +552,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "string_terms" : { "terms" : { "field" : "unmapped_string", "value_type" : "string", "missing": "abc" } } } } @@ -502,6 +578,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "boolean_terms" : { "terms" : { "field" : "unmapped_boolean", "value_type" : "boolean", "missing": true } } } } @@ -529,6 +606,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "unmapped_date", "value_type" : "date", "missing": "2016-05-11" } } } } @@ -556,6 +634,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "long_terms" : { "terms" : { "field" : "unmapped_long", "value_type" : "long", "missing": 3 } } } } @@ -581,6 +660,7 @@ setup: - do: search: + index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_terms" : { "terms" : { "field" : "unmapped_double", "value_type" : "double", "missing": 3.5 } } } } @@ -630,6 +710,7 @@ setup: - do: search: + index: test_1,test_2 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "number_terms" : { "terms" : { "field" : "number" } } } } @@ -1508,3 +1589,520 @@ Value type mismatch fails shard with no docs: - match: { aggregations.str_terms.buckets.2.doc_count: 1 } - match: { aggregations.str_terms.buckets.3.key: "192.168.0.3" } - match: { aggregations.str_terms.buckets.3.doc_count: 1 } + +--- +"terms order by top metrics null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[null_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: null_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: null_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } + +--- +"terms order by top metrics date not null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[birth_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: birth_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: birth_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "thomas" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } + + - match: { aggregations.name.buckets.1.key: "daniel" } + - match: { aggregations.name.buckets.1.doc_count: 3 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } + + - match: { aggregations.name.buckets.2.key: "alice" } + - match: { aggregations.name.buckets.2.doc_count: 2 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } + + - match: { aggregations.name.buckets.4.key: "mike" } + - match: { aggregations.name.buckets.4.doc_count: 1 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } + +--- +"terms order by top metrics numeric not null integer values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + +--- +"terms order by top metrics numeric not null double values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[price]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: price + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: price + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "bruce" } + - match: { aggregations.name.buckets.0.doc_count: 1 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } + + - match: { aggregations.name.buckets.1.key: "alice" } + - match: { aggregations.name.buckets.1.doc_count: 2 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } + + - match: { aggregations.name.buckets.2.key: "charlie" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } + + - match: { aggregations.name.buckets.3.key: "bob" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } + +--- +"terms order by top metrics size greater than 1": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 2 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort.0: "2021-10-24T18:37:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.metrics.score: 9 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort.0: "2021-08-09T17:22:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.metrics.score: 3 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort.0: "2021-11-22T18:47:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.metrics.score: 8 } + +--- +"terms order by top metrics missing metric": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. unknown metric \[unknown_metric\]/ + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[unknown_metric]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + +--- +"terms order by top metrics equal values sorted on term": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[version]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: version + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: version + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml index d21321dd2fff4..af48ebead5214 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml @@ -27,6 +27,67 @@ setup: { "index": {} } { "str": "pig" } + - do: + indices.create: + index: test_order_by_top_metrics + body: + settings: + number_of_replicas: 0 + mappings: + properties: + name: + type: keyword + birth_date: + type: date + null_date: + type: date + order_date: + type: date + score: + type: integer + version: + type: integer + price: + type: double + + - do: + bulk: + index: test_order_by_top_metrics + refresh: true + body: + - { "index": { } } + - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } + - { "index": { } } + - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } + - { "index": { } } + - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } + - { "index": { } } + - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } + - { "index": { } } + - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } + --- teardown: - do: @@ -113,3 +174,510 @@ enabled by default: - match: { aggregations.str_terms.buckets.2.key: pig } - match: { profile.shards.0.aggregations.0.type: /StringTermsAggregatorFromFilters/ } - match: { profile.shards.0.aggregations.0.description: str_terms } + +--- +"terms order by top metrics null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[null_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: null_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: null_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } + +--- +"terms order by top metrics date not null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[birth_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: birth_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: birth_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "thomas" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } + + - match: { aggregations.name.buckets.1.key: "daniel" } + - match: { aggregations.name.buckets.1.doc_count: 3 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } + + - match: { aggregations.name.buckets.2.key: "alice" } + - match: { aggregations.name.buckets.2.doc_count: 2 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } + + - match: { aggregations.name.buckets.4.key: "mike" } + - match: { aggregations.name.buckets.4.doc_count: 1 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } + +--- +"terms order by top metrics numeric not null integer values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + +--- +"terms order by top metrics numeric not null double values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[price]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: price + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: price + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "bruce" } + - match: { aggregations.name.buckets.0.doc_count: 1 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } + + - match: { aggregations.name.buckets.1.key: "alice" } + - match: { aggregations.name.buckets.1.doc_count: 2 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } + + - match: { aggregations.name.buckets.2.key: "charlie" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } + + - match: { aggregations.name.buckets.3.key: "bob" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } + +--- +"terms order by top metrics size greater than 1": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. \[top_metrics\] can only the be target if \[size\] is \[1\] but was \[2\]/ + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 2 + sort: + order_date: desc + +--- +"terms order by top metrics missing metric": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. Unknown metric name \[unknown_metric\] on multi-value metrics aggregation \[top_metrics\]/ + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[unknown_metric]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + +--- +"terms order by top metrics equal values sorted on term": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[version]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: version + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: version + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml new file mode 100644 index 0000000000000..fee7bb921b9d3 --- /dev/null +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml @@ -0,0 +1,615 @@ +setup: + - do: + indices.create: + index: test + body: + settings: + number_of_replicas: 0 + mappings: + properties: + name: + type: keyword + birth_date: + type: date + null_date: + type: date + order_date: + type: date + score: + type: integer + version: + type: integer + price: + type: double + + - do: + bulk: + index: test + refresh: true + body: + - { "index": { } } + - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } + - { "index": { } } + - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } + - { "index": { } } + - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } + - { "index": { } } + - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } + - { "index": { } } + - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } + +--- +teardown: + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: null + +--- +"terms order by top metrics null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + search: + index: test + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[null_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: null_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: null_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } + +--- +"terms order by top metrics date not null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + search: + index: test + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[birth_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: birth_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: birth_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "thomas" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } + + - match: { aggregations.name.buckets.1.key: "daniel" } + - match: { aggregations.name.buckets.1.doc_count: 3 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } + + - match: { aggregations.name.buckets.2.key: "alice" } + - match: { aggregations.name.buckets.2.doc_count: 2 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } + + - match: { aggregations.name.buckets.4.key: "mike" } + - match: { aggregations.name.buckets.4.doc_count: 1 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } + +--- +"terms order by top metrics numeric not null integer values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + search: + index: test + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + + +--- +"terms order by top metrics numeric not null double values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + search: + index: test + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[price]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: price + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: price + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "bruce" } + - match: { aggregations.name.buckets.0.doc_count: 1 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } + + - match: { aggregations.name.buckets.1.key: "alice" } + - match: { aggregations.name.buckets.1.doc_count: 2 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } + + - match: { aggregations.name.buckets.2.key: "charlie" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } + + - match: { aggregations.name.buckets.3.key: "bob" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } + +--- +"terms order by top metrics size greater than 1": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + search: + index: test + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 2 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort.0: "2021-10-24T18:37:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.metrics.score: 9 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort.0: "2021-08-09T17:22:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.metrics.score: 3 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort.0: "2021-11-22T18:47:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.metrics.score: 8 } + +--- +"terms order by top metrics missing metric": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. unknown metric \[unknown_metric\]/ + search: + index: test + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[unknown_metric]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + +--- +"terms order by top metrics equal values sorted on term": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + - do: + search: + index: test + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[version]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: version + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: version + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java index 7a3d8a497ea18..fe654c6ce8e39 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java @@ -293,6 +293,9 @@ static class DoubleMetricValues extends CollectingMetricValues { @Override public double doubleValue(long index) { + if (index < 0 || index >= values.size()) { + return Double.NaN; + } return values.get(index); } @@ -357,7 +360,7 @@ static class LongMetricValues extends CollectingMetricValues { @Override public double doubleValue(long index) { - if (empty.isEmpty(index)) { + if (empty.isEmpty(index) || index < 0 || index >= values.size()) { return Double.NaN; } return values.get(index); From 73269abdd908529c1c8548cf6f69825c702464ca Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:41:20 +0200 Subject: [PATCH 02/12] Update docs/changelog/85774.yaml --- docs/changelog/85774.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/85774.yaml diff --git a/docs/changelog/85774.yaml b/docs/changelog/85774.yaml new file mode 100644 index 0000000000000..0be85ca5b811c --- /dev/null +++ b/docs/changelog/85774.yaml @@ -0,0 +1,5 @@ +pr: 85774 +summary: "Fix: ordering terms aggregation on top metrics null values" +area: Aggregations +type: bug +issues: [] From c0990b0376894c5b4c24d169b5b1fc3fcfeb097f Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:42:25 +0200 Subject: [PATCH 03/12] test: remove test as a result of using existing yaml tests --- .../500_terms_order_by_top_metrics.yml | 615 ------------------ 1 file changed, 615 deletions(-) delete mode 100644 rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml deleted file mode 100644 index fee7bb921b9d3..0000000000000 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/500_terms_order_by_top_metrics.yml +++ /dev/null @@ -1,615 +0,0 @@ -setup: - - do: - indices.create: - index: test - body: - settings: - number_of_replicas: 0 - mappings: - properties: - name: - type: keyword - birth_date: - type: date - null_date: - type: date - order_date: - type: date - score: - type: integer - version: - type: integer - price: - type: double - - - do: - bulk: - index: test - refresh: true - body: - - { "index": { } } - - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } - - { "index": { } } - - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } - - { "index": { } } - - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } - - { "index": { } } - - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } - - { "index": { } } - - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } - - { "index": { } } - - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } - - { "index": { } } - - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } - ---- -teardown: - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: null - ---- -"terms order by top metrics null values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - search: - index: test - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[null_date]": desc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: null_date - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: null_date - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - match: { aggregations.name.buckets.0.key: "alice" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.1.key: "bob" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.2.key: "bruce" } - - match: { aggregations.name.buckets.2.doc_count: 1 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } - ---- -"terms order by top metrics date not null values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - search: - index: test - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[birth_date]": desc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: birth_date - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: birth_date - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "thomas" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } - - - match: { aggregations.name.buckets.1.key: "daniel" } - - match: { aggregations.name.buckets.1.doc_count: 3 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } - - - match: { aggregations.name.buckets.2.key: "alice" } - - match: { aggregations.name.buckets.2.doc_count: 2 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } - - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } - - - match: { aggregations.name.buckets.4.key: "mike" } - - match: { aggregations.name.buckets.4.doc_count: 1 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } - ---- -"terms order by top metrics numeric not null integer values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - search: - index: test - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[score]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "sophia" } - - match: { aggregations.name.buckets.0.doc_count: 3 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } - - - match: { aggregations.name.buckets.1.key: "bruce" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } - - - match: { aggregations.name.buckets.2.key: "daniel" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.3.key: "mike" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.4.key: "charlie" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } - - ---- -"terms order by top metrics numeric not null double values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - search: - index: test - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[price]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: price - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: price - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "bruce" } - - match: { aggregations.name.buckets.0.doc_count: 1 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } - - - match: { aggregations.name.buckets.1.key: "alice" } - - match: { aggregations.name.buckets.1.doc_count: 2 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } - - - match: { aggregations.name.buckets.2.key: "charlie" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } - - - match: { aggregations.name.buckets.3.key: "bob" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } - - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } - ---- -"terms order by top metrics size greater than 1": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - search: - index: test - body: - query: - match_all: {} - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[score]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 2 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "sophia" } - - match: { aggregations.name.buckets.0.doc_count: 3 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort.0: "2021-10-24T18:37:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.metrics.score: 9 } - - - match: { aggregations.name.buckets.1.key: "bruce" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } - - - match: { aggregations.name.buckets.2.key: "daniel" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 2 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort.0: "2021-08-09T17:22:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.metrics.score: 3 } - - - match: { aggregations.name.buckets.3.key: "mike" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.4.key: "charlie" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 2 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort.0: "2021-11-22T18:47:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.metrics.score: 8 } - ---- -"terms order by top metrics missing metric": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. unknown metric \[unknown_metric\]/ - search: - index: test - body: - query: - match_all: {} - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[unknown_metric]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 1 - sort: - order_date: desc - ---- -"terms order by top metrics equal values sorted on term": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - do: - search: - index: test - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[version]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: version - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: version - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "alice" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.1.key: "bob" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.2.key: "bruce" } - - match: { aggregations.name.buckets.2.doc_count: 1 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } From 0b93430c19770b34d4103b09d1e9e89b4a85d19e Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 11:54:57 +0200 Subject: [PATCH 04/12] fix: move top_metrics tests to x-pack --- .../test/search.aggregation/20_terms.yml | 598 -------------- .../22_terms_disable_opt.yml | 568 ------------- .../analytics/nested_top_metrics_sort.yml | 768 ++++++++++++++++++ 3 files changed, 768 insertions(+), 1166 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml index 0bc5ea2cf765d..119c5c8234441 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/20_terms.yml @@ -34,67 +34,6 @@ setup: number: type: double - - do: - indices.create: - index: test_order_by_top_metrics - body: - settings: - number_of_replicas: 0 - mappings: - properties: - name: - type: keyword - birth_date: - type: date - null_date: - type: date - order_date: - type: date - score: - type: integer - version: - type: integer - price: - type: double - - - do: - bulk: - index: test_order_by_top_metrics - refresh: true - body: - - { "index": { } } - - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } - - { "index": { } } - - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } - - { "index": { } } - - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } - - { "index": { } } - - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } - - { "index": { } } - - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } - - { "index": { } } - - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } - - { "index": { } } - - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } - - do: cluster.health: wait_for_status: green @@ -124,7 +63,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str" } } } } @@ -169,7 +107,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip" } } } } @@ -192,7 +129,6 @@ setup: - do: search: rest_total_hits_as_int: true - index: test_1 body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "include" : [ "127.0.0.1" ] } } } } - match: { hits.total: 3 } @@ -204,7 +140,6 @@ setup: - do: search: rest_total_hits_as_int: true - index: test_1 body: { "size" : 0, "aggs" : { "ip_terms" : { "terms" : { "field" : "ip", "exclude" : [ "127.0.0.1" ] } } } } - match: { hits.total: 3 } @@ -247,7 +182,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "boolean_terms" : { "terms" : { "field" : "boolean" } } } } @@ -292,7 +226,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "integer_terms" : { "terms" : { "field" : "integer" } } } } @@ -337,7 +270,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_terms" : { "terms" : { "field" : "double" } } } } @@ -382,7 +314,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date" } } } } @@ -404,7 +335,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date", "include" : [ "2016-05-03" ] } } } } @@ -418,7 +348,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "date", "exclude" : [ "2016-05-03" ] } } } } @@ -456,7 +385,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "include" : {"partition": 0, "num_partitions": 2 } } } } } @@ -472,7 +400,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "str", "include" : {"partition": 1, "num_partitions": 2 } } } } } @@ -512,7 +439,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "integer", "include" : {"partition": 0, "num_partitions": 2 } } } } } @@ -526,7 +452,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "str_terms" : { "terms" : { "field" : "integer", "include" : {"partition": 1, "num_partitions": 2 } } } } } @@ -552,7 +477,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "string_terms" : { "terms" : { "field" : "unmapped_string", "value_type" : "string", "missing": "abc" } } } } @@ -578,7 +502,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "boolean_terms" : { "terms" : { "field" : "unmapped_boolean", "value_type" : "boolean", "missing": true } } } } @@ -606,7 +529,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "date_terms" : { "terms" : { "field" : "unmapped_date", "value_type" : "date", "missing": "2016-05-11" } } } } @@ -634,7 +556,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "long_terms" : { "terms" : { "field" : "unmapped_long", "value_type" : "long", "missing": 3 } } } } @@ -660,7 +581,6 @@ setup: - do: search: - index: test_1 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "double_terms" : { "terms" : { "field" : "unmapped_double", "value_type" : "double", "missing": 3.5 } } } } @@ -710,7 +630,6 @@ setup: - do: search: - index: test_1,test_2 rest_total_hits_as_int: true body: { "size" : 0, "aggs" : { "number_terms" : { "terms" : { "field" : "number" } } } } @@ -1589,520 +1508,3 @@ Value type mismatch fails shard with no docs: - match: { aggregations.str_terms.buckets.2.doc_count: 1 } - match: { aggregations.str_terms.buckets.3.key: "192.168.0.3" } - match: { aggregations.str_terms.buckets.3.doc_count: 1 } - ---- -"terms order by top metrics null values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[null_date]": desc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: null_date - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: null_date - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - match: { aggregations.name.buckets.0.key: "alice" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.1.key: "bob" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.2.key: "bruce" } - - match: { aggregations.name.buckets.2.doc_count: 1 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } - ---- -"terms order by top metrics date not null values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[birth_date]": desc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: birth_date - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: birth_date - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "thomas" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } - - - match: { aggregations.name.buckets.1.key: "daniel" } - - match: { aggregations.name.buckets.1.doc_count: 3 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } - - - match: { aggregations.name.buckets.2.key: "alice" } - - match: { aggregations.name.buckets.2.doc_count: 2 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } - - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } - - - match: { aggregations.name.buckets.4.key: "mike" } - - match: { aggregations.name.buckets.4.doc_count: 1 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } - ---- -"terms order by top metrics numeric not null integer values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[score]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "sophia" } - - match: { aggregations.name.buckets.0.doc_count: 3 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } - - - match: { aggregations.name.buckets.1.key: "bruce" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } - - - match: { aggregations.name.buckets.2.key: "daniel" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.3.key: "mike" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.4.key: "charlie" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } - ---- -"terms order by top metrics numeric not null double values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[price]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: price - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: price - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "bruce" } - - match: { aggregations.name.buckets.0.doc_count: 1 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } - - - match: { aggregations.name.buckets.1.key: "alice" } - - match: { aggregations.name.buckets.1.doc_count: 2 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } - - - match: { aggregations.name.buckets.2.key: "charlie" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } - - - match: { aggregations.name.buckets.3.key: "bob" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } - - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } - ---- -"terms order by top metrics size greater than 1": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - search: - index: test_order_by_top_metrics - body: - query: - match_all: {} - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[score]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 2 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "sophia" } - - match: { aggregations.name.buckets.0.doc_count: 3 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort.0: "2021-10-24T18:37:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.metrics.score: 9 } - - - match: { aggregations.name.buckets.1.key: "bruce" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } - - - match: { aggregations.name.buckets.2.key: "daniel" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 2 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort.0: "2021-08-09T17:22:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.metrics.score: 3 } - - - match: { aggregations.name.buckets.3.key: "mike" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.4.key: "charlie" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 2 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort.0: "2021-11-22T18:47:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.metrics.score: 8 } - ---- -"terms order by top metrics missing metric": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. unknown metric \[unknown_metric\]/ - search: - index: test_order_by_top_metrics - body: - query: - match_all: {} - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[unknown_metric]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 1 - sort: - order_date: desc - ---- -"terms order by top metrics equal values sorted on term": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[version]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: version - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: version - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "alice" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.1.key: "bob" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.2.key: "bruce" } - - match: { aggregations.name.buckets.2.doc_count: 1 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml index af48ebead5214..d21321dd2fff4 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/22_terms_disable_opt.yml @@ -27,67 +27,6 @@ setup: { "index": {} } { "str": "pig" } - - do: - indices.create: - index: test_order_by_top_metrics - body: - settings: - number_of_replicas: 0 - mappings: - properties: - name: - type: keyword - birth_date: - type: date - null_date: - type: date - order_date: - type: date - score: - type: integer - version: - type: integer - price: - type: double - - - do: - bulk: - index: test_order_by_top_metrics - refresh: true - body: - - { "index": { } } - - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } - - { "index": { } } - - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } - - { "index": { } } - - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } - - { "index": { } } - - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } - - { "index": { } } - - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } - - { "index": { } } - - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } - - { "index": { } } - - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } - - { "index": { } } - - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } - - { "index": { } } - - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } - - { "index": { } } - - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } - --- teardown: - do: @@ -174,510 +113,3 @@ enabled by default: - match: { aggregations.str_terms.buckets.2.key: pig } - match: { profile.shards.0.aggregations.0.type: /StringTermsAggregatorFromFilters/ } - match: { profile.shards.0.aggregations.0.description: str_terms } - ---- -"terms order by top metrics null values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[null_date]": desc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: null_date - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: null_date - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - match: { aggregations.name.buckets.0.key: "alice" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.1.key: "bob" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.2.key: "bruce" } - - match: { aggregations.name.buckets.2.doc_count: 1 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } - ---- -"terms order by top metrics date not null values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[birth_date]": desc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: birth_date - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: birth_date - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "thomas" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } - - - match: { aggregations.name.buckets.1.key: "daniel" } - - match: { aggregations.name.buckets.1.doc_count: 3 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } - - - match: { aggregations.name.buckets.2.key: "alice" } - - match: { aggregations.name.buckets.2.doc_count: 2 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } - - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } - - - match: { aggregations.name.buckets.4.key: "mike" } - - match: { aggregations.name.buckets.4.doc_count: 1 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } - ---- -"terms order by top metrics numeric not null integer values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[score]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "sophia" } - - match: { aggregations.name.buckets.0.doc_count: 3 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } - - - match: { aggregations.name.buckets.1.key: "bruce" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } - - - match: { aggregations.name.buckets.2.key: "daniel" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.3.key: "mike" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } - - - match: { aggregations.name.buckets.4.key: "charlie" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } - ---- -"terms order by top metrics numeric not null double values": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[price]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: price - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: price - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "bruce" } - - match: { aggregations.name.buckets.0.doc_count: 1 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } - - - match: { aggregations.name.buckets.1.key: "alice" } - - match: { aggregations.name.buckets.1.doc_count: 2 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } - - - match: { aggregations.name.buckets.2.key: "charlie" } - - match: { aggregations.name.buckets.2.doc_count: 3 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } - - - match: { aggregations.name.buckets.3.key: "bob" } - - match: { aggregations.name.buckets.3.doc_count: 1 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } - - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } - ---- -"terms order by top metrics size greater than 1": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. \[top_metrics\] can only the be target if \[size\] is \[1\] but was \[2\]/ - search: - index: test_order_by_top_metrics - body: - query: - match_all: {} - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[score]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 2 - sort: - order_date: desc - ---- -"terms order by top metrics missing metric": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. Unknown metric name \[unknown_metric\] on multi-value metrics aggregation \[top_metrics\]/ - search: - index: test_order_by_top_metrics - body: - query: - match_all: {} - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[unknown_metric]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: score - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: score - size: 1 - sort: - order_date: desc - ---- -"terms order by top metrics equal values sorted on term": - - skip: - version: " - 8.1.99" - reason: Bug fixed in 8.2.0 - - - do: - cluster.put_settings: - body: - persistent: - search.aggs.rewrite_to_filter_by_filter: false - - - do: - search: - index: test_order_by_top_metrics - body: - size: 0 - aggs: - name: - terms: - field: name - order: - "field_exists>top_metrics[version]": asc - size: 5 - aggs: - field_exists: - filter: - bool: - filter: - - bool: - should: - - exists: - field: version - minimum_should_match: 1 - aggs: - top_metrics: - top_metrics: - metrics: - field: version - size: 1 - sort: - order_date: desc - - - match: { hits.total.value: 16 } - - match: { hits.total.relation: "eq" } - - length: { aggregations.name.buckets: 5 } - - - match: { aggregations.name.buckets.0.key: "alice" } - - match: { aggregations.name.buckets.0.doc_count: 2 } - - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } - - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.1.key: "bob" } - - match: { aggregations.name.buckets.1.doc_count: 1 } - - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } - - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.2.key: "bruce" } - - match: { aggregations.name.buckets.2.doc_count: 1 } - - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } - - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.3.key: "charlie" } - - match: { aggregations.name.buckets.3.doc_count: 3 } - - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } - - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } - - - match: { aggregations.name.buckets.4.key: "daniel" } - - match: { aggregations.name.buckets.4.doc_count: 3 } - - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } - - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } - - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index b203ea7ba8e46..40ec6bb8f2b9a 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -20,6 +20,30 @@ setup: type: long version: type: keyword + + - do: + indices.create: + index: test_order_by_top_metrics + body: + settings: + number_of_replicas: 0 + mappings: + properties: + name: + type: keyword + birth_date: + type: date + null_date: + type: date + order_date: + type: date + score: + type: integer + version: + type: integer + price: + type: double + - do: bulk: index: test @@ -38,13 +62,67 @@ setup: - '{ "index": {} }' - '{ "timestamp": "2021-10-02", "metric": 1, "name": "third", "uuid": "0003", "version": "v1" }' + - do: + bulk: + index: test_order_by_top_metrics + refresh: true + body: + - { "index": { } } + - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } + - { "index": { } } + - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } + - { "index": { } } + - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } + - { "index": { } } + - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } + - { "index": { } } + - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } + - { "index": { } } + - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } + - { "index": { } } + - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } + - { "index": { } } + - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } + - { "index": { } } + - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } + +--- +teardown: + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: null + --- "sort on top metrics keyword same version": - skip: version: " - 8.1.99" reason: bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: search: + index: test body: size: 0 aggs: @@ -87,8 +165,16 @@ setup: - skip: version: " - 8.1.99" reason: bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: search: + index: test body: size: 0 aggs: @@ -130,8 +216,16 @@ setup: - skip: version: " - 8.1.99" reason: bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: search: + index: test body: size: 0 aggs: @@ -173,8 +267,16 @@ setup: - skip: version: " - 8.1.99" reason: bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: search: + index: test body: size: 0 aggs: @@ -216,9 +318,17 @@ setup: - skip: version: " - 8.1.99" reason: bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: search: body: + index: test size: 0 aggs: hits: @@ -259,9 +369,17 @@ setup: - skip: version: " - 8.1.99" reason: bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: catch: /unknown metric \[unknown\]/ search: + index: test body: size: 0 aggs: @@ -278,3 +396,653 @@ setup: metrics: - { field: metric } - { field: name } + +--- +"terms order by top metrics null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[null_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: null_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: null_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 0 } + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 0 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 0 } + +--- +"terms order by top metrics date not null values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[birth_date]": desc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: birth_date + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: birth_date + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "thomas" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-27T18:29:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.birth_date: "1991-10-27T00:00:00.000Z" } + + - match: { aggregations.name.buckets.1.key: "daniel" } + - match: { aggregations.name.buckets.1.doc_count: 3 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.birth_date: "1991-09-11T00:00:00.000Z" } + + - match: { aggregations.name.buckets.2.key: "alice" } + - match: { aggregations.name.buckets.2.doc_count: 2 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.birth_date: "1990-12-10T00:00:00.000Z" } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.birth_date: "1990-08-22T00:00:00.000Z" } + + - match: { aggregations.name.buckets.4.key: "mike" } + - match: { aggregations.name.buckets.4.doc_count: 1 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.birth_date: "1990-06-18T00:00:00.000Z" } + +--- +"terms order by top metrics numeric not null integer values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + +--- +"terms order by top metrics numeric not null double values": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[price]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: price + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: price + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "bruce" } + - match: { aggregations.name.buckets.0.doc_count: 1 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.price: 9.49 } + + - match: { aggregations.name.buckets.1.key: "alice" } + - match: { aggregations.name.buckets.1.doc_count: 2 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.price: 12.90 } + + - match: { aggregations.name.buckets.2.key: "charlie" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.price: 22.50 } + + - match: { aggregations.name.buckets.3.key: "bob" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.price: 34.20 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } + +--- +"terms order by top metrics size greater than 1": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + + - do: + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 2 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "sophia" } + - match: { aggregations.name.buckets.0.doc_count: 3 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-12-11T12:13:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.score: 3 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.sort.0: "2021-10-24T18:37:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.1.metrics.score: 9 } + + - match: { aggregations.name.buckets.1.key: "bruce" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.score: 4 } + + - match: { aggregations.name.buckets.2.key: "daniel" } + - match: { aggregations.name.buckets.2.doc_count: 3 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.score: 5 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.sort.0: "2021-08-09T17:22:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.1.metrics.score: 3 } + + - match: { aggregations.name.buckets.3.key: "mike" } + - match: { aggregations.name.buckets.3.doc_count: 1 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-11-11T15:22:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.score: 5 } + + - match: { aggregations.name.buckets.4.key: "charlie" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 2 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.score: 6 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.sort.0: "2021-11-22T18:47:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.metrics.score: 8 } + +--- +"terms order by top metrics missing metric": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. unknown metric \[unknown_metric\]/ + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[unknown_metric]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc + +--- +"terms order by top metrics equal values sorted on term": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: true + + - do: + search: + index: test_order_by_top_metrics + body: + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[version]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: version + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: version + size: 1 + sort: + order_date: desc + + - match: { hits.total.value: 16 } + - match: { hits.total.relation: "eq" } + - length: { aggregations.name.buckets: 5 } + + - match: { aggregations.name.buckets.0.key: "alice" } + - match: { aggregations.name.buckets.0.doc_count: 2 } + - match: { aggregations.name.buckets.0.field_exists.doc_count: 2 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.sort.0: "2021-09-09T17:50:00.000Z" } + - match: { aggregations.name.buckets.0.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.1.key: "bob" } + - match: { aggregations.name.buckets.1.doc_count: 1 } + - match: { aggregations.name.buckets.1.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.sort.0: "2021-10-12T18:39:00.000Z" } + - match: { aggregations.name.buckets.1.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.2.key: "bruce" } + - match: { aggregations.name.buckets.2.doc_count: 1 } + - match: { aggregations.name.buckets.2.field_exists.doc_count: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.sort.0: "2021-08-29T18:47:00.000Z" } + - match: { aggregations.name.buckets.2.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.3.key: "charlie" } + - match: { aggregations.name.buckets.3.doc_count: 3 } + - match: { aggregations.name.buckets.3.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.sort.0: "2021-12-10T19:33:00.000Z" } + - match: { aggregations.name.buckets.3.field_exists.top_metrics.top.0.metrics.version: 1 } + + - match: { aggregations.name.buckets.4.key: "daniel" } + - match: { aggregations.name.buckets.4.doc_count: 3 } + - match: { aggregations.name.buckets.4.field_exists.doc_count: 3 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top: 1 } + - length: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort: 1 } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.sort.0: "2021-11-09T17:29:00.000Z" } + - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } + +--- +"terms order by top metrics size greater than 1": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. \[top_metrics\] can only the be target if \[size\] is \[1\] but was \[2\]/ + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[score]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 2 + sort: + order_date: desc + +--- +"terms order by top metrics missing metric": + - skip: + version: " - 8.1.99" + reason: Bug fixed in 8.2.0 + + - do: + cluster.put_settings: + body: + persistent: + search.aggs.rewrite_to_filter_by_filter: false + + - do: + catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. Unknown metric name \[unknown_metric\] on multi-value metrics aggregation \[top_metrics\]/ + search: + index: test_order_by_top_metrics + body: + query: + match_all: {} + size: 0 + aggs: + name: + terms: + field: name + order: + "field_exists>top_metrics[unknown_metric]": asc + size: 5 + aggs: + field_exists: + filter: + bool: + filter: + - bool: + should: + - exists: + field: score + minimum_should_match: 1 + aggs: + top_metrics: + top_metrics: + metrics: + field: score + size: 1 + sort: + order_date: desc From 60c41a3eef6356d98dab5b04a11a38a2b18f158e Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 11:56:27 +0200 Subject: [PATCH 05/12] fix: duplicate yaml test name --- .../rest-api-spec/test/analytics/nested_top_metrics_sort.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index 40ec6bb8f2b9a..6f54a882baba5 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -823,7 +823,7 @@ teardown: - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.1.metrics.score: 8 } --- -"terms order by top metrics missing metric": +"terms order by top metrics missing metric rewrite_to_filter_by_filter true": - skip: version: " - 8.1.99" reason: Bug fixed in 8.2.0 @@ -1002,7 +1002,7 @@ teardown: order_date: desc --- -"terms order by top metrics missing metric": +"terms order by top metrics missing metric rewrite_to_filter_by_filter false": - skip: version: " - 8.1.99" reason: Bug fixed in 8.2.0 From abb5fe20aa6d26444125a0b26eec00fc577326e9 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 12:03:03 +0200 Subject: [PATCH 06/12] fix: duplicate yaml test name --- .../rest-api-spec/test/analytics/nested_top_metrics_sort.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index 6f54a882baba5..b3613dd26f3b1 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -725,7 +725,7 @@ teardown: - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.price: 59.19 } --- -"terms order by top metrics size greater than 1": +"terms order by top metrics size greater than 1 rewrite_to_filter_by_filter true": - skip: version: " - 8.1.99" reason: Bug fixed in 8.2.0 @@ -956,7 +956,7 @@ teardown: - match: { aggregations.name.buckets.4.field_exists.top_metrics.top.0.metrics.version: 1 } --- -"terms order by top metrics size greater than 1": +"terms order by top metrics size greater than 1 rewrite_to_filter_by_filter false": - skip: version: " - 8.1.99" reason: Bug fixed in 8.2.0 From f7c0df844f3790b81e0a70249d6559aad75bc1e4 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 14:06:38 +0200 Subject: [PATCH 07/12] fix: move index out of body inside search --- .../rest-api-spec/test/analytics/nested_top_metrics_sort.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index b3613dd26f3b1..b684c007ccbe9 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -327,8 +327,8 @@ teardown: - do: search: + index: test body: - index: test size: 0 aggs: hits: From db8d5e0e4ee9bf171445f03d24c1f10d7d39f484 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:28:33 +0200 Subject: [PATCH 08/12] fix: use the unknown_metric in top_metrics agg --- .../test/analytics/nested_top_metrics_sort.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index b684c007ccbe9..04c323a9127dc 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -847,7 +847,7 @@ teardown: terms: field: name order: - "field_exists>top_metrics[unknown_metric]": asc + "field_exists>top_metrics[score]": asc size: 5 aggs: field_exists: @@ -857,7 +857,7 @@ teardown: - bool: should: - exists: - field: score + field: unknown_metric minimum_should_match: 1 aggs: top_metrics: @@ -1026,7 +1026,7 @@ teardown: terms: field: name order: - "field_exists>top_metrics[unknown_metric]": asc + "field_exists>top_metrics[score]": asc size: 5 aggs: field_exists: @@ -1036,7 +1036,7 @@ teardown: - bool: should: - exists: - field: score + field: unknown_metric minimum_should_match: 1 aggs: top_metrics: From c6d9edb27681ec6874246d3e4595a60dcc071b00 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Mon, 11 Apr 2022 16:21:05 +0200 Subject: [PATCH 09/12] fix: use the unknown_metric in top_metrics agg --- .../test/analytics/nested_top_metrics_sort.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index 04c323a9127dc..fe776652122b2 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -857,13 +857,13 @@ teardown: - bool: should: - exists: - field: unknown_metric + field: score minimum_should_match: 1 aggs: top_metrics: top_metrics: metrics: - field: score + field: unknown_metric size: 1 sort: order_date: desc @@ -1036,13 +1036,13 @@ teardown: - bool: should: - exists: - field: unknown_metric + field: score minimum_should_match: 1 aggs: top_metrics: top_metrics: metrics: - field: score + field: unknown_metric size: 1 sort: order_date: desc From bbbcf94df2b260f86d382adde69fa78ca75a271d Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Tue, 12 Apr 2022 09:56:46 +0200 Subject: [PATCH 10/12] fix: use actual field names for non existing metrics --- .../test/analytics/nested_top_metrics_sort.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index fe776652122b2..e0f2b74cdb8d7 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -835,7 +835,7 @@ teardown: search.aggs.rewrite_to_filter_by_filter: true - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. unknown metric \[unknown_metric\]/ + catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. unknown metric [score]/ search: index: test_order_by_top_metrics body: @@ -863,7 +863,7 @@ teardown: top_metrics: top_metrics: metrics: - field: unknown_metric + field: price size: 1 sort: order_date: desc @@ -1014,7 +1014,7 @@ teardown: search.aggs.rewrite_to_filter_by_filter: false - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[unknown_metric\]\]. Unknown metric name \[unknown_metric\] on multi-value metrics aggregation \[top_metrics\]/ + catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. Unknown metric name \[score\] on multi-value metrics aggregation \[top_metrics\]/ search: index: test_order_by_top_metrics body: @@ -1042,7 +1042,7 @@ teardown: top_metrics: top_metrics: metrics: - field: unknown_metric + field: price size: 1 sort: order_date: desc From fc02ec5072ea492e4bc4d0e99536da1224803687 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Tue, 12 Apr 2022 09:59:08 +0200 Subject: [PATCH 11/12] fix: code format --- .../analytics/nested_top_metrics_sort.yml | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index e0f2b74cdb8d7..e63cbef3ff1fe 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -67,37 +67,37 @@ setup: index: test_order_by_top_metrics refresh: true body: - - { "index": { } } + - { "index": {} } - { "name": "alice", "order_date": "2021-09-09T17:50:00.000Z", birth_date: "1990-12-10", score: 7, version: 1, price: 12.90 } - - { "index": { } } + - { "index": {} } - { "name": "bob", "order_date": "2021-10-12T18:39:00.000Z", birth_date: "1989-11-04", score: 9, version: 1, price: 34.20 } - - { "index": { } } + - { "index": {} } - { "name": "charlie", "order_date": "2021-12-10T19:33:00.000Z", birth_date: "1990-08-22", score: 6, version: 1, price: 22.50 } - - { "index": { } } + - { "index": {} } - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1991-09-11", score: 3, version: 1, price: 18.49 } - - { "index": { } } + - { "index": {} } - { "name": "sophia", "order_date": "2021-09-02T16:44:00.000Z", birth_date: "1989-04-05", score: 6, version: 1, price: 90.00 } - - { "index": { } } + - { "index": {} } - { "name": "mike", "order_date": "2021-11-11T15:22:00.000Z", birth_date: "1990-06-18", score: 5, version: 1, price: 77.80 } - - { "index": { } } + - { "index": {} } - { "name": "thomas", "order_date": "2021-08-11T18:11:00.000Z", birth_date: "1991-10-27", score: 4, version: 1, price: 7.99 } - - { "index": { } } + - { "index": {} } - { "name": "bruce", "order_date": "2021-08-29T18:47:00.000Z", birth_date: "1990-01-17", score: 4, version: 1, price: 9.49 } - - { "index": { } } + - { "index": {} } - { "name": "alice", "order_date": "2021-08-11T17:22:00.000Z", birth_date: "1990-12-10", score: 5, version: 1, price: 14.99 } - - { "index": { } } + - { "index": {} } - { "name": "charlie", "order_date": "2021-11-22T18:47:00.000Z", birth_date: "1990-08-22", score: 8, version: 1, price: 24.90 } - - { "index": { } } + - { "index": {} } - { "name": "charlie", "order_date": "2021-08-10T18:31:00.000Z", birth_date: "1990-08-22", score: 7, version: 1, price: 49.19 } - - { "index": { } } + - { "index": {} } - { "name": "daniel", "order_date": "2021-11-09T17:29:00.000Z", birth_date: "1991-09-11", score: 5, version: 1, price: 59.19 } - - { "index": { } } + - { "index": {} } - { "name": "sophia", "order_date": "2021-12-11T12:13:00.000Z", birth_date: "1989-04-05", score: 3, version: 1, price: 99.89 } - - { "index": { } } + - { "index": {} } - { "name": "daniel", "order_date": "2021-08-09T17:22:00.000Z", birth_date: "1990-09-11", score: 4, version: 1, price: 119.00 } - - { "index": { } } + - { "index": {} } - { "name": "thomas", "order_date": "2021-09-27T18:29:00.000Z", birth_date: "1991-10-27", score: 8, version: 1, price: 79.90 } - - { "index": { } } + - { "index": {} } - { "name": "sophia", "order_date": "2021-10-24T18:37:00.000Z", birth_date: "1989-04-05", score: 9, version: 1, price: 19.99 } --- From 6d6e01940016d78d3fdc35cc555438710b36ae87 Mon Sep 17 00:00:00 2001 From: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com> Date: Tue, 12 Apr 2022 10:48:31 +0200 Subject: [PATCH 12/12] fix: escape square brakets --- .../rest-api-spec/test/analytics/nested_top_metrics_sort.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml index e63cbef3ff1fe..fc4c69d07ec5f 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/nested_top_metrics_sort.yml @@ -835,7 +835,7 @@ teardown: search.aggs.rewrite_to_filter_by_filter: true - do: - catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. unknown metric [score]/ + catch: /Invalid aggregation order path \[field_exists>top_metrics\[score\]\]. unknown metric \[score\]/ search: index: test_order_by_top_metrics body: