Browse Source

CONSOLEify some more aggregation docs

Related #18160
Zachary Tong 8 years ago
parent
commit
a2845c86fe

+ 0 - 2
docs/build.gradle

@@ -25,14 +25,12 @@ apply plugin: 'elasticsearch.docs-test'
  * entirely and have a party! There will be cake and everything.... */
 buildRestTests.expectedUnconvertedCandidates = [
   'reference/aggregations/bucket/iprange-aggregation.asciidoc',
-  'reference/aggregations/bucket/missing-aggregation.asciidoc',
   'reference/aggregations/bucket/nested-aggregation.asciidoc',
   'reference/aggregations/bucket/range-aggregation.asciidoc',
   'reference/aggregations/bucket/reverse-nested-aggregation.asciidoc',
   'reference/aggregations/bucket/significantterms-aggregation.asciidoc',
   'reference/aggregations/bucket/terms-aggregation.asciidoc',
   'reference/aggregations/matrix/stats-aggregation.asciidoc',
-  'reference/aggregations/metrics/cardinality-aggregation.asciidoc',
   'reference/aggregations/metrics/extendedstats-aggregation.asciidoc',
   'reference/aggregations/metrics/percentile-aggregation.asciidoc',
   'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',

+ 6 - 3
docs/reference/aggregations/bucket/missing-aggregation.asciidoc

@@ -7,6 +7,7 @@ Example:
 
 [source,js]
 --------------------------------------------------
+POST /sales/_search?size=0
 {
     "aggs" : {
         "products_without_a_price" : {
@@ -15,6 +16,8 @@ Example:
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:sales]
 
 In the above example, we get the total number of products that do not have a price.
 
@@ -24,11 +27,11 @@ Response:
 --------------------------------------------------
 {
     ...
-
-    "aggs" : {
+    "aggregations" : {
         "products_without_a_price" : {
-            "doc_count" : 10
+            "doc_count" : 00
         }
     }
 }
 --------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]

+ 39 - 10
docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc

@@ -10,16 +10,34 @@ match a query:
 
 [source,js]
 --------------------------------------------------
+POST /sales/_search?size=0
 {
     "aggs" : {
-        "author_count" : {
+        "type_count" : {
             "cardinality" : {
-                "field" : "author"
+                "field" : "type"
             }
         }
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:sales]
+
+Response:
+
+[source,js]
+--------------------------------------------------
+{
+    ...
+    "aggregations" : {
+        "type_count" : {
+            "value" : 3
+        }
+    }
+}
+--------------------------------------------------
+// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
 
 ==== Precision control
 
@@ -29,17 +47,20 @@ experimental[The `precision_threshold` option is specific to the current interna
 
 [source,js]
 --------------------------------------------------
+POST /sales/_search?size=0
 {
     "aggs" : {
-        "author_count" : {
+        "type_count" : {
             "cardinality" : {
-                "field" : "author_hash",
+                "field" : "type",
                 "precision_threshold": 100 <1>
             }
         }
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:sales]
 
 <1> The `precision_threshold` options allows to trade memory for accuracy, and
 defines a unique count below which counts are expected to be close to
@@ -159,33 +180,37 @@ however since hashes need to be computed on the fly.
 
 [source,js]
 --------------------------------------------------
+POST /sales/_search?size=0
 {
     "aggs" : {
-        "author_count" : {
+        "type_promoted_count" : {
             "cardinality" : {
                 "script": {
                     "lang": "painless",
-                    "inline": "doc['author.first_name'].value + ' ' + doc['author.last_name'].value"
+                    "inline": "doc['type'].value + ' ' + doc['promoted'].value"
                 }
             }
         }
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[setup:sales]
 
 This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax:
 
 [source,js]
 --------------------------------------------------
+POST /sales/_search?size=0
 {
     "aggs" : {
-        "author_count" : {
+        "type_promoted_count" : {
             "cardinality" : {
                 "script" : {
                     "file": "my_script",
                     "params": {
-                        "first_name_field": "author.first_name",
-                        "last_name_field": "author.last_name"
+                        "type_field": "type",
+                        "promoted_field": "promoted"
                     }
                 }
             }
@@ -193,6 +218,8 @@ This will interpret the `script` parameter as an `inline` script with the `painl
     }
 }
 --------------------------------------------------
+// CONSOLE
+// TEST[skip:no script]
 
 TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
 
@@ -204,6 +231,7 @@ had a value.
 
 [source,js]
 --------------------------------------------------
+POST /sales/_search?size=0
 {
     "aggs" : {
         "tag_cardinality" : {
@@ -215,5 +243,6 @@ had a value.
     }
 }
 --------------------------------------------------
-
+// CONSOLE
+// TEST[setup:sales]
 <1> Documents without a value in the `tag` field will fall into the same bucket as documents that have the value `N/A`.