From de1fac8ceb35fa5df3b3fcc4a54f3d035da43b76 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 15 Aug 2017 15:55:58 -0400 Subject: [PATCH 1/2] Add REST tests for avg/min/max/sum agg metrics Related to #26220 --- .../search.aggregation/100_avg_metric.yml | 176 ++++++++++++++++++ .../search.aggregation/110_max_metric.yml | 175 +++++++++++++++++ .../search.aggregation/120_min_metric.yml | 176 ++++++++++++++++++ .../search.aggregation/130_sum_metric.yml | 176 ++++++++++++++++++ 4 files changed, 703 insertions(+) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml new file mode 100644 index 0000000000000..1d444e2132f7d --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml @@ -0,0 +1,176 @@ +setup: + - do: + indices.create: + index: test_1 + body: + settings: + number_of_replicas: 0 + mappings: + test: + properties: + int_field: + type : integer + double_field: + type : double + string_field: + type: keyword + - do: + cluster.health: + wait_for_status: green + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 2 + body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 3 + body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 4 + body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } + + - do: + indices.refresh: {} +--- +"Basic test": + + - do: + search: + body: + aggs: + the_int_avg: + avg: + field: int_field + the_double_avg: + avg: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_avg.value: 76.0 } + - match: { aggregations.the_double_avg.value: 76.0 } + +--- +"Only aggs test": + + - do: + search: + body: + size: 0 + aggs: + the_int_avg: + avg: + field: int_field + the_double_avg: + avg: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 0 } + - match: { aggregations.the_int_avg.value: 76.0 } + - match: { aggregations.the_double_avg.value: 76.0 } + +--- +"Filtered test": + + - do: + search: + body: + query: + constant_score: + filter: + range: + int_field: + gte: 50 + aggs: + the_int_avg: + avg: + field: int_field + the_double_avg: + avg: + field: double_field + + - match: { hits.total: 3 } + - length: { hits.hits: 3 } + - match: { aggregations.the_int_avg.value: 101.0 } + - match: { aggregations.the_double_avg.value: 101.0 } + + +--- +"Missing field with missing param": + + - do: + search: + body: + aggs: + the_missing_avg: + avg: + field: foo + missing: 1 + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_missing_avg.value: 1 } + +--- +"Missing field without missing param": + + - do: + search: + body: + aggs: + the_missing_avg: + avg: + field: foo + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - is_false: aggregations.the_missing_avg.value + +--- +"Metadata test": + + - do: + search: + body: + aggs: + the_int_avg: + meta: + foo: bar + avg: + field: int_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_avg.value: 76.0 } + - match: { aggregations.the_int_avg.meta.foo: "bar" } + +--- +"Aggregating wrong datatype test": + + - do: + catch: request + search: + body: + aggs: + the_string_avg: + avg: + field: string_field + diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml new file mode 100644 index 0000000000000..3bf57df1b0595 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml @@ -0,0 +1,175 @@ +setup: + - do: + indices.create: + index: test_1 + body: + settings: + number_of_replicas: 0 + mappings: + test: + properties: + int_field: + type : integer + double_field: + type : double + string_field: + type: keyword + - do: + cluster.health: + wait_for_status: green + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 2 + body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 3 + body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 4 + body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } + + - do: + indices.refresh: {} +--- +"Basic test": + + - do: + search: + body: + aggs: + the_int_max: + max: + field: int_field + the_double_max: + max: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_max.value: 151.0 } + - match: { aggregations.the_double_max.value: 151.0 } + +--- +"Only aggs test": + + - do: + search: + body: + size: 0 + aggs: + the_int_max: + max: + field: int_field + the_double_max: + max: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 0 } + - match: { aggregations.the_int_max.value: 151.0 } + - match: { aggregations.the_double_max.value: 151.0 } + +--- +"Filtered test": + + - do: + search: + body: + query: + constant_score: + filter: + range: + int_field: + lte: 60 + aggs: + the_int_max: + max: + field: int_field + the_double_max: + max: + field: double_field + + - match: { hits.total: 2 } + - length: { hits.hits: 2 } + - match: { aggregations.the_int_max.value: 51.0 } + - match: { aggregations.the_double_max.value: 51.0 } + + +--- +"Missing field with missing param": + + - do: + search: + body: + aggs: + the_missing_max: + max: + field: foo + missing: 1 + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_missing_max.value: 1 } + +--- +"Missing field without missing param": + + - do: + search: + body: + aggs: + the_missing_max: + max: + field: foo + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - is_false: aggregations.the_missing_max.value + +--- +"Metadata test": + + - do: + search: + body: + aggs: + the_int_max: + meta: + foo: bar + max: + field: int_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_max.value: 151.0 } + - match: { aggregations.the_int_max.meta.foo: "bar" } + +--- +"Aggregating wrong datatype test": + + - do: + catch: request + search: + body: + aggs: + the_string_avg: + avg: + field: string_field diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml new file mode 100644 index 0000000000000..899ca5c2e68be --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml @@ -0,0 +1,176 @@ +setup: + - do: + indices.create: + index: test_1 + body: + settings: + number_of_replicas: 0 + mappings: + test: + properties: + int_field: + type : integer + double_field: + type : double + string_field: + type: keyword + - do: + cluster.health: + wait_for_status: green + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 2 + body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 3 + body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 4 + body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } + + - do: + indices.refresh: {} +--- +"Basic test": + + - do: + search: + body: + aggs: + the_int_min: + min: + field: int_field + the_double_min: + min: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_min.value: 1.0 } + - match: { aggregations.the_double_min.value: 1.0 } + +--- +"Only aggs test": + + - do: + search: + body: + size: 0 + aggs: + the_int_min: + min: + field: int_field + the_double_min: + min: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 0 } + - match: { aggregations.the_int_min.value: 1.0 } + - match: { aggregations.the_double_min.value: 1.0 } + +--- +"Filtered test": + + - do: + search: + body: + query: + constant_score: + filter: + range: + int_field: + gte: 50 + aggs: + the_int_min: + min: + field: int_field + the_double_min: + min: + field: double_field + + - match: { hits.total: 3 } + - length: { hits.hits: 3 } + - match: { aggregations.the_int_min.value: 51.0 } + - match: { aggregations.the_double_min.value: 51.0 } + + +--- +"Missing field with missing param": + + - do: + search: + body: + aggs: + the_missing_min: + min: + field: foo + missing: 1 + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_missing_min.value: 1.0 } + +--- +"Missing field without missing param": + + - do: + search: + body: + aggs: + the_missing_min: + min: + field: foo + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - is_false: aggregations.the_missing_min.value + +--- +"Metadata test": + + - do: + search: + body: + aggs: + the_int_min: + meta: + foo: bar + min: + field: int_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_min.value: 1.0 } + - match: { aggregations.the_int_min.meta.foo: "bar" } + +--- +"Aggregating wrong datatype test": + + - do: + catch: request + search: + body: + aggs: + the_string_min: + min: + field: string_field + diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml new file mode 100644 index 0000000000000..1869e7bbcd0cd --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml @@ -0,0 +1,176 @@ +setup: + - do: + indices.create: + index: test_1 + body: + settings: + number_of_replicas: 0 + mappings: + test: + properties: + int_field: + type : integer + double_field: + type : double + string_field: + type: keyword + - do: + cluster.health: + wait_for_status: green + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 2 + body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 3 + body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } + + - do: + index: + index: test_1 + type: test + id: 4 + body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } + + - do: + indices.refresh: {} +--- +"Basic test": + + - do: + search: + body: + aggs: + the_int_sum: + sum: + field: int_field + the_double_sum: + sum: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_sum.value: 304.0 } + - match: { aggregations.the_double_sum.value: 304.0 } + +--- +"Only aggs test": + + - do: + search: + body: + size: 0 + aggs: + the_int_sum: + sum: + field: int_field + the_double_sum: + sum: + field: double_field + + - match: { hits.total: 4 } + - length: { hits.hits: 0 } + - match: { aggregations.the_int_sum.value: 304.0 } + - match: { aggregations.the_double_sum.value: 304.0 } + +--- +"Filtered test": + + - do: + search: + body: + query: + constant_score: + filter: + range: + int_field: + gte: 50 + aggs: + the_int_sum: + sum: + field: int_field + the_double_sum: + sum: + field: double_field + + - match: { hits.total: 3 } + - length: { hits.hits: 3 } + - match: { aggregations.the_int_sum.value: 303.0 } + - match: { aggregations.the_double_sum.value: 303.0 } + + +--- +"Missing field with missing param": + + - do: + search: + body: + aggs: + the_missing_sum: + sum: + field: foo + missing: 1 + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_missing_sum.value: 4.0 } + +--- +"Missing field without missing param": + + - do: + search: + body: + aggs: + the_missing_sum: + sum: + field: foo + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_missing_sum.value: 0.0 } + +--- +"Metadata test": + + - do: + search: + body: + aggs: + the_int_sum: + meta: + foo: bar + sum: + field: int_field + + - match: { hits.total: 4 } + - length: { hits.hits: 4 } + - match: { aggregations.the_int_sum.value: 304.0 } + - match: { aggregations.the_int_sum.meta.foo: "bar" } + +--- +"Aggregating wrong datatype test": + + - do: + catch: request + search: + body: + aggs: + the_string_sum: + sum: + field: string_field + From 6ff945f4720e410846ce7e969671e232115adb27 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 15 Aug 2017 16:47:49 -0400 Subject: [PATCH 2/2] Review cleanup --- .../search.aggregation/100_avg_metric.yml | 62 +++++++++--------- .../search.aggregation/110_max_metric.yml | 64 +++++++++---------- .../search.aggregation/120_min_metric.yml | 64 +++++++++---------- .../search.aggregation/130_sum_metric.yml | 64 +++++++++---------- 4 files changed, 124 insertions(+), 130 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml index 1d444e2132f7d..5aec7f9e67c66 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml @@ -14,40 +14,40 @@ setup: type : double string_field: type: keyword - - do: - cluster.health: - wait_for_status: green - - - do: - index: - index: test_1 - type: test - id: 1 - body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 2 - body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 3 - body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } - do: - index: - index: test_1 - type: test - id: 4 - body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } + bulk: + refresh: true + body: + - index: + _index: test_1 + _type: test + _id: 1 + - int_field: 1 + double_field: 1.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 2 + - int_field: 51 + double_field: 51.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 3 + - int_field: 101 + double_field: 101.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 4 + - int_field: 151 + double_field: 151.0 + string_field: foo - - do: - indices.refresh: {} --- "Basic test": diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml index 3bf57df1b0595..f3134f7bc857b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml @@ -15,39 +15,37 @@ setup: string_field: type: keyword - do: - cluster.health: - wait_for_status: green - - - do: - index: - index: test_1 - type: test - id: 1 - body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 2 - body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 3 - body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 4 - body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } - - - do: - indices.refresh: {} + bulk: + refresh: true + body: + - index: + _index: test_1 + _type: test + _id: 1 + - int_field: 1 + double_field: 1.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 2 + - int_field: 51 + double_field: 51.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 3 + - int_field: 101 + double_field: 101.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 4 + - int_field: 151 + double_field: 151.0 + string_field: foo --- "Basic test": diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml index 899ca5c2e68be..26444bf0feb4b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml @@ -15,39 +15,37 @@ setup: string_field: type: keyword - do: - cluster.health: - wait_for_status: green - - - do: - index: - index: test_1 - type: test - id: 1 - body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 2 - body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 3 - body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 4 - body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } - - - do: - indices.refresh: {} + bulk: + refresh: true + body: + - index: + _index: test_1 + _type: test + _id: 1 + - int_field: 1 + double_field: 1.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 2 + - int_field: 51 + double_field: 51.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 3 + - int_field: 101 + double_field: 101.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 4 + - int_field: 151 + double_field: 151.0 + string_field: foo --- "Basic test": diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml index 1869e7bbcd0cd..ae26ac7d30c7d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml @@ -15,39 +15,37 @@ setup: string_field: type: keyword - do: - cluster.health: - wait_for_status: green - - - do: - index: - index: test_1 - type: test - id: 1 - body: { "int_field" : 1, "double_field": 1.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 2 - body: { "int_field" : 51, "double_field": 51.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 3 - body: { "int_field" : 101, "double_field": 101.0, "string_field": "foo" } - - - do: - index: - index: test_1 - type: test - id: 4 - body: { "int_field" : 151, "double_field": 151.0, "string_field": "foo" } - - - do: - indices.refresh: {} + bulk: + refresh: true + body: + - index: + _index: test_1 + _type: test + _id: 1 + - int_field: 1 + double_field: 1.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 2 + - int_field: 51 + double_field: 51.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 3 + - int_field: 101 + double_field: 101.0 + string_field: foo + - index: + _index: test_1 + _type: test + _id: 4 + - int_field: 151 + double_field: 151.0 + string_field: foo --- "Basic test":