Browse Source

[DOCS] Update sum aggregation for histograms (#84493) (#84496)

Fixes an error and test snippets for the sum aggregation example for histograms.

Closes #84491

Co-authored-by: James Rodewig <40268737+jrodewig@users.noreply.github.com>
(cherry picked from commit fb45ac9deae7053c8925cd90afebad150f3fdf06)

Co-authored-by: Maja Grubic <maja.grubic@elastic.co>
James Rodewig 3 years ago
parent
commit
74e4add3a8
1 changed files with 21 additions and 11 deletions
  1. 21 11
      docs/reference/aggregations/metrics/sum-aggregation.asciidoc

+ 21 - 11
docs/reference/aggregations/metrics/sum-aggregation.asciidoc

@@ -138,25 +138,34 @@ For example, for the following index that stores pre-aggregated histograms with
 
 [source,console]
 --------------------------------------------------
-PUT metrics_index/_doc/1
+PUT metrics_index
+{
+  "mappings": {
+    "properties": {
+      "latency_histo": { "type": "histogram" }
+    }
+  }
+}
+
+PUT metrics_index/_doc/1?refresh
 {
   "network.name" : "net-1",
   "latency_histo" : {
-      "values" : [0.1, 0.2, 0.3, 0.4, 0.5], <1>
-      "counts" : [3, 7, 23, 12, 6] <2>
+      "values" : [0.1, 0.2, 0.3, 0.4, 0.5],
+      "counts" : [3, 7, 23, 12, 6]
    }
 }
 
-PUT metrics_index/_doc/2
+PUT metrics_index/_doc/2?refresh
 {
   "network.name" : "net-2",
   "latency_histo" : {
-      "values" :  [0.1, 0.2, 0.3, 0.4, 0.5], <1>
-      "counts" : [8, 17, 8, 7, 6] <2>
+      "values" :  [0.1, 0.2, 0.3, 0.4, 0.5],
+      "counts" : [8, 17, 8, 7, 6]
    }
 }
 
-POST /metrics_index/_search?size=0
+POST /metrics_index/_search?size=0&filter_path=aggregations
 {
   "aggs" : {
     "total_latency" : { "sum" : { "field" : "latency_histo" } }
@@ -164,13 +173,15 @@ POST /metrics_index/_search?size=0
 }
 --------------------------------------------------
 
-For each histogram field the `sum` aggregation will multiply each number in the `values` array <1> multiplied by its associated count
-in the `counts` array <2>. Eventually, it will add all values for all histograms and return the following result:
+For each histogram field, the `sum` aggregation will add each number in the
+`values` array, multiplied by its associated count in the `counts` array.
+
+Eventually, it will add all values for all histograms and return the following
+result:
 
 [source,console-result]
 --------------------------------------------------
 {
-  ...
   "aggregations": {
     "total_latency": {
       "value": 28.8
@@ -178,4 +189,3 @@ in the `counts` array <2>. Eventually, it will add all values for all histograms
   }
 }
 --------------------------------------------------
-// TESTRESPONSE[skip:test not setup]