Browse Source

Add REST tests for value_count, stats, extended_stats and cardinality aggs (#26239)

* Add REST tests for value_count, stats, extended_stats and cardinality aggs

Also updates the document type of of other agg REST tests to `doc`

Related to #26220
Zachary Tong 8 years ago
parent
commit
67e003da0d

+ 5 - 5
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/100_avg_metric.yml

@@ -6,7 +6,7 @@ setup:
             settings:
               number_of_replicas: 0
             mappings:
-              test:
+              doc:
                 properties:
                   int_field:
                      type : integer
@@ -21,28 +21,28 @@ setup:
          body:
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    1
            - int_field: 1
              double_field: 1.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    2
            - int_field: 51
              double_field: 51.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    3
            - int_field: 101
              double_field: 101.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    4
            - int_field: 151
              double_field: 151.0

+ 7 - 5
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/110_max_metric.yml

@@ -6,7 +6,7 @@ setup:
             settings:
               number_of_replicas: 0
             mappings:
-              test:
+              doc:
                 properties:
                   int_field:
                      type : integer
@@ -14,38 +14,40 @@ setup:
                      type : double
                   string_field:
                      type: keyword
+
   - do:
        bulk:
          refresh: true
          body:
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    1
            - int_field: 1
              double_field: 1.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    2
            - int_field: 51
              double_field: 51.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    3
            - int_field: 101
              double_field: 101.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    4
            - int_field: 151
              double_field: 151.0
              string_field: foo
+
 ---
 "Basic test":
 

+ 7 - 5
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/120_min_metric.yml

@@ -6,7 +6,7 @@ setup:
             settings:
               number_of_replicas: 0
             mappings:
-              test:
+              doc:
                 properties:
                   int_field:
                      type : integer
@@ -14,38 +14,40 @@ setup:
                      type : double
                   string_field:
                      type: keyword
+
   - do:
        bulk:
          refresh: true
          body:
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    1
            - int_field: 1
              double_field: 1.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    2
            - int_field: 51
              double_field: 51.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    3
            - int_field: 101
              double_field: 101.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    4
            - int_field: 151
              double_field: 151.0
              string_field: foo
+
 ---
 "Basic test":
 

+ 7 - 5
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/130_sum_metric.yml

@@ -6,7 +6,7 @@ setup:
             settings:
               number_of_replicas: 0
             mappings:
-              test:
+              doc:
                 properties:
                   int_field:
                      type : integer
@@ -14,38 +14,40 @@ setup:
                      type : double
                   string_field:
                      type: keyword
+
   - do:
        bulk:
          refresh: true
          body:
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    1
            - int_field: 1
              double_field: 1.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    2
            - int_field: 51
              double_field: 51.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    3
            - int_field: 101
              double_field: 101.0
              string_field: foo
            - index:
                _index: test_1
-               _type:  test
+               _type:  doc
                _id:    4
            - int_field: 151
              double_field: 151.0
              string_field: foo
+
 ---
 "Basic test":
 

+ 175 - 0
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/140_value_count_metric.yml

@@ -0,0 +1,175 @@
+setup:
+  - do:
+      indices.create:
+          index: test_1
+          body:
+            settings:
+              number_of_replicas: 0
+            mappings:
+              doc:
+                properties:
+                  int_field:
+                     type : integer
+                  double_field:
+                     type : double
+                  string_field:
+                     type: keyword
+
+  - do:
+       bulk:
+         refresh: true
+         body:
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    1
+           - int_field: 1
+             double_field: 1.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    2
+           - int_field: 51
+             double_field: 51.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    3
+           - int_field: 101
+             double_field: 101.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    4
+           - int_field: 151
+             double_field: 151.0
+             string_field: foo
+
+---
+"Basic test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_value_count:
+              value_count:
+                field: int_field
+            the_double_value_count:
+              value_count:
+                field: double_field
+            the_string_value_count:
+              value_count:
+                field: string_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_value_count.value: 4 }
+  - match: { aggregations.the_double_value_count.value: 4 }
+  - match: { aggregations.the_string_value_count.value: 4 }
+
+---
+"Only aggs test":
+
+  - do:
+      search:
+        body:
+          size: 0
+          aggs:
+            the_int_value_count:
+              value_count:
+                field: int_field
+            the_double_value_count:
+              value_count:
+                field: double_field
+            the_string_value_count:
+              value_count:
+                field: string_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 0 }
+  - match: { aggregations.the_int_value_count.value: 4 }
+  - match: { aggregations.the_double_value_count.value: 4 }
+  - match: { aggregations.the_string_value_count.value: 4 }
+
+---
+"Filtered test":
+
+  - do:
+      search:
+        body:
+          query:
+            constant_score:
+              filter:
+                range:
+                  int_field:
+                    gte: 50
+          aggs:
+            the_int_value_count:
+              value_count:
+                field: int_field
+            the_double_value_count:
+              value_count:
+                field: double_field
+            the_string_value_count:
+              value_count:
+                field: string_field
+
+  - match: { hits.total: 3 }
+  - length: { hits.hits: 3 }
+  - match: { aggregations.the_int_value_count.value: 3 }
+  - match: { aggregations.the_double_value_count.value: 3 }
+  - match: { aggregations.the_string_value_count.value: 3 }
+
+
+---
+"Missing field with missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_missing_value_count:
+              value_count:
+                field: foo
+                missing: 1
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_missing_value_count.value: 4 }
+
+---
+"Missing field without missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_missing_value_count:
+              value_count:
+                field: foo
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - is_false: aggregations.the_missing_value_count.value
+
+---
+"Metadata test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_value_count:
+              meta:
+                foo: bar
+              value_count:
+                field: int_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_value_count.value: 4 }
+  - match: { aggregations.the_int_value_count.meta.foo: "bar" }

+ 196 - 0
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/150_stats_metric.yml

@@ -0,0 +1,196 @@
+setup:
+  - do:
+      indices.create:
+          index: test_1
+          body:
+            settings:
+              number_of_replicas: 0
+            mappings:
+              doc:
+                properties:
+                  int_field:
+                     type : integer
+                  double_field:
+                     type : double
+                  string_field:
+                     type: keyword
+
+  - do:
+       bulk:
+         refresh: true
+         body:
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    1
+           - int_field: 1
+             double_field: 1.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    2
+           - int_field: 51
+             double_field: 51.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    3
+           - int_field: 101
+             double_field: 101.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    4
+           - int_field: 151
+             double_field: 151.0
+             string_field: foo
+
+---
+"Basic test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_stats:
+              stats:
+                field: int_field
+            the_double_stats:
+              stats:
+                field: double_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_stats.count: 4 }
+  - match: { aggregations.the_int_stats.min: 1.0 }
+  - match: { aggregations.the_int_stats.max: 151.0 }
+  - match: { aggregations.the_int_stats.avg: 76.0 }
+  - match: { aggregations.the_int_stats.sum: 304.0 }
+  - match: { aggregations.the_double_stats.count: 4 }
+  - match: { aggregations.the_double_stats.min: 1.0 }
+  - match: { aggregations.the_double_stats.max: 151.0 }
+  - match: { aggregations.the_double_stats.avg: 76.0 }
+  - match: { aggregations.the_double_stats.sum: 304.0 }
+
+---
+"Only aggs test":
+
+  - do:
+      search:
+        body:
+          size: 0
+          aggs:
+            the_int_stats:
+              stats:
+                field: int_field
+            the_double_stats:
+              stats:
+                field: double_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 0 }
+  - match: { aggregations.the_int_stats.count: 4 }
+  - match: { aggregations.the_int_stats.min: 1.0 }
+  - match: { aggregations.the_int_stats.max: 151.0 }
+  - match: { aggregations.the_int_stats.avg: 76.0 }
+  - match: { aggregations.the_int_stats.sum: 304.0 }
+  - match: { aggregations.the_double_stats.count: 4 }
+  - match: { aggregations.the_double_stats.min: 1.0 }
+  - match: { aggregations.the_double_stats.max: 151.0 }
+  - match: { aggregations.the_double_stats.avg: 76.0 }
+  - match: { aggregations.the_double_stats.sum: 304.0 }
+
+---
+"Filtered test":
+
+  - do:
+      search:
+        body:
+          query:
+            constant_score:
+              filter:
+                range:
+                  int_field:
+                    gte: 50
+          aggs:
+            the_int_stats:
+              stats:
+                field: int_field
+            the_double_stats:
+              stats:
+                field: double_field
+
+  - match: { hits.total: 3 }
+  - length: { hits.hits: 3 }
+  - match: { aggregations.the_int_stats.count: 3 }
+  - match: { aggregations.the_int_stats.min: 51.0 }
+  - match: { aggregations.the_int_stats.max: 151.0 }
+  - match: { aggregations.the_int_stats.avg: 101.0 }
+  - match: { aggregations.the_int_stats.sum: 303.0 }
+  - match: { aggregations.the_double_stats.count: 3 }
+  - match: { aggregations.the_double_stats.min: 51.0 }
+  - match: { aggregations.the_double_stats.max: 151.0 }
+  - match: { aggregations.the_double_stats.avg: 101.0 }
+  - match: { aggregations.the_double_stats.sum: 303.0 }
+
+
+---
+"Missing field with missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_missing_stats:
+              stats:
+                field: foo
+                missing: 1
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_missing_stats.count: 4 }
+  - match: { aggregations.the_missing_stats.min: 1.0 }
+  - match: { aggregations.the_missing_stats.max: 1.0 }
+  - match: { aggregations.the_missing_stats.avg: 1.0 }
+  - match: { aggregations.the_missing_stats.sum: 4.0 }
+
+---
+"Missing field without missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_missing_stats:
+              stats:
+                field: foo
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - is_false: aggregations.the_missing_stats.value
+
+---
+"Metadata test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_stats:
+              meta:
+                foo: bar
+              stats:
+                field: int_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_stats.count: 4 }
+  - match: { aggregations.the_int_stats.min: 1.0 }
+  - match: { aggregations.the_int_stats.max: 151.0 }
+  - match: { aggregations.the_int_stats.avg: 76.0 }
+  - match: { aggregations.the_int_stats.sum: 304.0 }
+
+

+ 291 - 0
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/160_extended_stats_metric.yml

@@ -0,0 +1,291 @@
+setup:
+  - do:
+      indices.create:
+          index: test_1
+          body:
+            settings:
+              number_of_replicas: 0
+            mappings:
+              doc:
+                properties:
+                  int_field:
+                     type : integer
+                  double_field:
+                     type : double
+                  string_field:
+                     type: keyword
+
+  - do:
+       bulk:
+         refresh: true
+         body:
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    1
+           - int_field: 1
+             double_field: 1.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    2
+           - int_field: 51
+             double_field: 51.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    3
+           - int_field: 101
+             double_field: 101.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    4
+           - int_field: 151
+             double_field: 151.0
+             string_field: foo
+
+---
+"Basic test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_extended_stats:
+              extended_stats:
+                field: int_field
+            the_double_extended_stats:
+              extended_stats:
+                field: double_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_extended_stats.count: 4 }
+  - match: { aggregations.the_int_extended_stats.min: 1.0 }
+  - match: { aggregations.the_int_extended_stats.max: 151.0 }
+  - match: { aggregations.the_int_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_int_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_int_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_int_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.upper: 187.80339887498948 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.lower: -35.80339887498948 }
+  - match: { aggregations.the_double_extended_stats.count: 4 }
+  - match: { aggregations.the_double_extended_stats.min: 1.0 }
+  - match: { aggregations.the_double_extended_stats.max: 151.0 }
+  - match: { aggregations.the_double_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_double_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_double_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_double_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.upper: 187.80339887498948 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.lower: -35.80339887498948 }
+
+---
+"Only aggs test":
+
+  - do:
+      search:
+        body:
+          size: 0
+          aggs:
+            the_int_extended_stats:
+              extended_stats:
+                field: int_field
+            the_double_extended_stats:
+              extended_stats:
+                field: double_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 0 }
+  - match: { aggregations.the_int_extended_stats.count: 4 }
+  - match: { aggregations.the_int_extended_stats.min: 1.0 }
+  - match: { aggregations.the_int_extended_stats.max: 151.0 }
+  - match: { aggregations.the_int_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_int_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_int_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_int_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_int_extended_stats.variance: 3125.0 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.upper: 187.80339887498948 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.lower: -35.80339887498948 }
+  - match: { aggregations.the_double_extended_stats.count: 4 }
+  - match: { aggregations.the_double_extended_stats.min: 1.0 }
+  - match: { aggregations.the_double_extended_stats.max: 151.0 }
+  - match: { aggregations.the_double_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_double_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_double_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_double_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_double_extended_stats.variance: 3125.0 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.upper: 187.80339887498948 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.lower: -35.80339887498948 }
+
+---
+"Filtered test":
+
+  - do:
+      search:
+        body:
+          query:
+            constant_score:
+              filter:
+                range:
+                  int_field:
+                    gte: 50
+          aggs:
+            the_int_extended_stats:
+              extended_stats:
+                field: int_field
+            the_double_extended_stats:
+              extended_stats:
+                field: double_field
+
+  - match: { hits.total: 3 }
+  - length: { hits.hits: 3 }
+  - match: { aggregations.the_int_extended_stats.count: 3 }
+  - match: { aggregations.the_int_extended_stats.min: 51.0 }
+  - match: { aggregations.the_int_extended_stats.max: 151.0 }
+  - match: { aggregations.the_int_extended_stats.avg: 101.0 }
+  - match: { aggregations.the_int_extended_stats.sum: 303.0 }
+  - match: { aggregations.the_int_extended_stats.sum_of_squares: 35603.0 }
+  - match: { aggregations.the_int_extended_stats.variance: 1666.6666666666667 }
+  - match: { aggregations.the_int_extended_stats.std_deviation: 40.824829046386306 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.upper: 182.6496580927726 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.lower: 19.35034190722739 }
+  - match: { aggregations.the_double_extended_stats.count: 3 }
+  - match: { aggregations.the_double_extended_stats.min: 51.0 }
+  - match: { aggregations.the_double_extended_stats.max: 151.0 }
+  - match: { aggregations.the_double_extended_stats.avg: 101.0 }
+  - match: { aggregations.the_double_extended_stats.sum: 303.0 }
+  - match: { aggregations.the_double_extended_stats.sum_of_squares: 35603.0 }
+  - match: { aggregations.the_double_extended_stats.variance: 1666.6666666666667 }
+  - match: { aggregations.the_double_extended_stats.std_deviation: 40.824829046386306 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.upper: 182.6496580927726 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.lower: 19.35034190722739 }
+
+
+---
+"Missing field with missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_missing_extended_stats:
+              extended_stats:
+                field: foo
+                missing: 1
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_missing_extended_stats.count: 4 }
+  - match: { aggregations.the_missing_extended_stats.min: 1.0 }
+  - match: { aggregations.the_missing_extended_stats.max: 1.0 }
+  - match: { aggregations.the_missing_extended_stats.avg: 1.0 }
+  - match: { aggregations.the_missing_extended_stats.sum: 4.0 }
+  - match: { aggregations.the_missing_extended_stats.sum_of_squares: 4.0 }
+  - match: { aggregations.the_missing_extended_stats.variance: 0.0 }
+  - match: { aggregations.the_missing_extended_stats.std_deviation: 0.0 }
+  - match: { aggregations.the_missing_extended_stats.std_deviation_bounds.upper: 1.0 }
+  - match: { aggregations.the_missing_extended_stats.std_deviation_bounds.lower: 1.0 }
+
+---
+"Missing field without missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_missing_extended_stats:
+              extended_stats:
+                field: foo
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - is_false: aggregations.the_missing_extended_stats.value
+
+---
+"Metadata test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_extended_stats:
+              meta:
+                foo: bar
+              extended_stats:
+                field: int_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_extended_stats.count: 4 }
+  - match: { aggregations.the_int_extended_stats.min: 1.0 }
+  - match: { aggregations.the_int_extended_stats.max: 151.0 }
+  - match: { aggregations.the_int_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_int_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_int_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_int_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.upper: 187.80339887498948 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.lower: -35.80339887498948 }
+
+---
+"Sigma test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            the_int_extended_stats:
+              extended_stats:
+                field: int_field
+                sigma: 3
+            the_double_extended_stats:
+              extended_stats:
+                field: double_field
+                sigma: 3
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.the_int_extended_stats.count: 4 }
+  - match: { aggregations.the_int_extended_stats.min: 1.0 }
+  - match: { aggregations.the_int_extended_stats.max: 151.0 }
+  - match: { aggregations.the_int_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_int_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_int_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_int_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.upper: 243.7050983124842 }
+  - match: { aggregations.the_int_extended_stats.std_deviation_bounds.lower: -91.70509831248421 }
+  - match: { aggregations.the_double_extended_stats.count: 4 }
+  - match: { aggregations.the_double_extended_stats.min: 1.0 }
+  - match: { aggregations.the_double_extended_stats.max: 151.0 }
+  - match: { aggregations.the_double_extended_stats.avg: 76.0 }
+  - match: { aggregations.the_double_extended_stats.sum: 304.0 }
+  - match: { aggregations.the_double_extended_stats.sum_of_squares: 35604.0 }
+  - match: { aggregations.the_double_extended_stats.std_deviation: 55.90169943749474 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.upper: 243.7050983124842 }
+  - match: { aggregations.the_double_extended_stats.std_deviation_bounds.lower: -91.70509831248421 }
+
+---
+"Bad sigma test":
+
+  - do:
+      catch: /\[sigma\] must be greater than or equal to 0. Found \[-1.0\] in \[the_int_extended_stats\]/
+      search:
+        body:
+          aggs:
+            the_int_extended_stats:
+              extended_stats:
+                field: int_field
+                sigma: -1
+
+  - do:
+      catch: /parsing_exception/
+      search:
+        body:
+          aggs:
+            the_int_extended_stats:
+              extended_stats:
+                field: int_field
+                sigma: "foo"

+ 213 - 0
rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/170_cardinality_metric.yml

@@ -0,0 +1,213 @@
+setup:
+  - do:
+      indices.create:
+          index: test_1
+          body:
+            settings:
+              number_of_replicas: 0
+            mappings:
+              doc:
+                properties:
+                  int_field:
+                     type : integer
+                  double_field:
+                     type : double
+                  string_field:
+                     type: keyword
+
+  - do:
+       bulk:
+         refresh: true
+         body:
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    1
+           - int_field: 1
+             double_field: 1.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    2
+           - int_field: 51
+             double_field: 51.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    3
+           - int_field: 101
+             double_field: 101.0
+             string_field: foo
+           - index:
+               _index: test_1
+               _type:  doc
+               _id:    4
+           - int_field: 151
+             double_field: 151.0
+             string_field: foo
+
+---
+"Basic test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            distinct_int:
+              cardinality:
+                field: int_field
+            distinct_double:
+              cardinality:
+                field: double_field
+            distinct_string:
+              cardinality:
+                field: string_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.distinct_int.value: 4 }
+  - match: { aggregations.distinct_double.value: 4 }
+  - match: { aggregations.distinct_string.value: 1 }
+
+  - do:
+      search:
+        body:
+          aggs:
+            distinct_int:
+              cardinality:
+                field: int_field
+                precision_threshold: 100
+            distinct_double:
+              cardinality:
+                field: double_field
+                precision_threshold: 100
+            distinct_string:
+              cardinality:
+                field: string_field
+                precision_threshold: 100
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.distinct_int.value: 4 }
+  - match: { aggregations.distinct_double.value: 4 }
+  - match: { aggregations.distinct_string.value: 1 }
+
+---
+"Only aggs test":
+
+  - do:
+      search:
+        body:
+          size: 0
+          aggs:
+            distinct_int:
+              cardinality:
+                field: int_field
+            distinct_double:
+              cardinality:
+                field: double_field
+            distinct_string:
+              cardinality:
+                field: string_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 0 }
+  - match: { aggregations.distinct_int.value: 4 }
+  - match: { aggregations.distinct_double.value: 4 }
+  - match: { aggregations.distinct_string.value: 1 }
+
+---
+"Filtered test":
+
+  - do:
+      search:
+        body:
+          query:
+            constant_score:
+              filter:
+                range:
+                  int_field:
+                    gte: 50
+          aggs:
+            distinct_int:
+              cardinality:
+                field: int_field
+            distinct_double:
+              cardinality:
+                field: double_field
+            distinct_string:
+              cardinality:
+                field: string_field
+
+  - match: { hits.total: 3 }
+  - length: { hits.hits: 3 }
+  - match: { aggregations.distinct_int.value: 3 }
+  - match: { aggregations.distinct_double.value: 3 }
+  - match: { aggregations.distinct_string.value: 1 }
+
+
+---
+"Missing field with missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            distinct_missing:
+              cardinality:
+                field: missing_field
+                missing: "foo"
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.distinct_missing.value: 1 }
+
+---
+"Missing field without missing param":
+
+  - do:
+      search:
+        body:
+          aggs:
+            distinct_missing:
+              cardinality:
+                field: missing_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - is_false: aggregations.distinct_missing.value
+
+---
+"Metadata test":
+
+  - do:
+      search:
+        body:
+          aggs:
+            distinct_missing:
+              meta:
+                foo: bar
+              cardinality:
+                field: int_field
+
+  - match: { hits.total: 4 }
+  - length: { hits.hits: 4 }
+  - match: { aggregations.distinct_missing.value: 4 }
+  - match: { aggregations.distinct_missing.meta.foo: "bar" }
+
+---
+"Invalid Precision test":
+
+  - do:
+      catch: /\[precisionThreshold\] must be greater than or equal to 0. Found \[-1\] in \[distinct_int\]/
+      search:
+        body:
+          aggs:
+            distinct_int:
+              cardinality:
+                field: int_field
+                precision_threshold: -1
+
+