From ac8d08706e27d419346a928aeb6a172c5c8736be Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Sun, 26 Mar 2017 19:32:33 +0530 Subject: [PATCH 1/4] Update aggs reference documentation for 'keyed' options Add 'keyed' parameter documentation for following: - Date Histogram Aggregation - Date Range Aggregation - Geo Distance Aggregation - Histogram Aggregation - IP range aggregation - Percentiles Aggregation - Percentile Ranks Aggregation --- .../bucket/datehistogram-aggregation.asciidoc | 55 +++++++++ .../bucket/daterange-aggregation.asciidoc | 88 ++++++++++++++ .../bucket/geodistance-aggregation.asciidoc | 108 ++++++++++++++++++ .../bucket/histogram-aggregation.asciidoc | 55 +++++++++ .../bucket/iprange-aggregation.asciidoc | 90 +++++++++++++++ .../metrics/percentile-aggregation.asciidoc | 45 ++++++++ .../percentile-rank-aggregation.asciidoc | 46 ++++++++ 7 files changed, 487 insertions(+) diff --git a/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc index d2ae9052f3536..2b900bd9ba2cc 100644 --- a/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc @@ -302,6 +302,61 @@ documents into buckets starting at 6am: NOTE: The start `offset` of each bucket is calculated after the `time_zone` adjustments have been made. +==== Keyed Response + +Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "nyc_accident_histogram": { + "date_histogram": { + "field": "date", + "interval" : "year", + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "nyc_accident_histogram": { + "buckets": { + "2013-01-01T00:00:00.000Z": { + "key_as_string": "2013-01-01T00:00:00.000Z", + "key": 1356998400000, + "doc_count": 203733 + }, + "2014-01-01T00:00:00.000Z": { + "key_as_string": "2014-01-01T00:00:00.000Z", + "key": 1388534400000, + "doc_count": 205929 + }, + "2015-01-01T00:00:00.000Z": { + "key_as_string": "2015-01-01T00:00:00.000Z", + "key": 1420070400000, + "doc_count": 217637 + }, + "2016-01-01T00:00:00.000Z": { + "key_as_string": "2016-01-01T00:00:00.000Z", + "key": 1451606400000, + "doc_count": 227656 + } + } + } + } +} +-------------------------------------------------- + ==== Scripts Like with the normal <>, both document level scripts and diff --git a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc index df32075583fbf..b7d0828d36e71 100644 --- a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc @@ -153,3 +153,91 @@ POST /sales/_search?size=0 <1> This date will be converted to `2016-02-15T00:00:00.000+01:00`. <2> `now/d` will be rounded to the beginning of the day in the CET time zone. + +==== Keyed Response + +Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array: + +[source,js] +-------------------------------------------------- +{ + "aggs" : { + "nyc_recent_accidents": { + "date_range": { + "field": "@timestamp", + "format": "MM-yyy", + "ranges": [ + { "from": "now-10M/d", "to": "now" } + ], + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "nyc_recent_accidents": { + "buckets": { + "05-2016-03-2017": { + "from": 1464307200000, + "from_as_string": "05-2016", + "to": 1490604059606, + "to_as_string": "03-2017", + "doc_count": 185436 + } + } + } + } +} +-------------------------------------------------- + +It is also possible to customize the key for each range: + +[source,js] +-------------------------------------------------- +{ + "aggs" : { + "nyc_recent_accidents": { + "date_range": { + "field": "@timestamp", + "format": "MM-yyy", + "ranges": [ + { "from": "now-10M/d", "to": "now" } + ], + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "nyc_recent_accidents": { + "buckets": { + "last-10M": { + "from": 1464307200000, + "from_as_string": "05-2016", + "to": 1490604059606, + "to_as_string": "03-2017", + "doc_count": 185436 + } + } + } + } +} +-------------------------------------------------- diff --git a/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc b/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc index a051fc00c4f2e..bb7964ea35c4c 100644 --- a/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc @@ -104,3 +104,111 @@ There are two distance calculation modes: `arc` (the default), and `plane`. The } } -------------------------------------------------- + +==== Keyed Response + +Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "accidents_near_empire_state": { + "geo_distance": { + "field": "coords", + "unit": "km", + "origin" : { "lat" : 40.7484, "lon" : -73.9857 }, + "ranges": [ + { "to": 3 }, + { "from" : 3, "to" : 8 }, + { "from" : 8 } + ], + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "accidents_near_empire_state": { + "buckets": { + "*-3.0": { + "from": 0, + "to": 3, + "doc_count": 102090 + }, + "3.0-8.0": { + "from": 3, + "to": 8, + "doc_count": 170287 + }, + "8.0-*": { + "from": 8, + "doc_count": 526590 + } + } + } + } +} +-------------------------------------------------- + +It is also possible to customize the key for each range: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "accidents_near_empire_state": { + "geo_distance": { + "field": "coords", + "unit": "km", + "origin" : { "lat" : 40.7484, "lon" : -73.9857 }, + "ranges": [ + { "key": "very-close", "to": 3 }, + { "key": "close", "from" : 3, "to" : 8 }, + { "key": "far", "from" : 8 } + ], + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "accidents_near_empire_state": { + "buckets": { + "very-close": { + "from": 0, + "to": 3, + "doc_count": 102090 + }, + "close": { + "from": 3, + "to": 8, + "doc_count": 170287 + }, + "far": { + "from": 8, + "doc_count": 526590 + } + } + } + } +} +-------------------------------------------------- diff --git a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc index de828c62aa9a7..4083fd9fe2cb1 100644 --- a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc @@ -362,6 +362,61 @@ Response: -------------------------------------------------- // TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] +==== Keyed Response + +Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "bytes_histogram": { + "histogram": { + "field": "bytes", + "interval": 200, + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "bytes_histogram": { + "buckets": { + "0.0": { + "key": 0, + "doc_count": 13596 + }, + "200.0": { + "key": 200, + "doc_count": 33882 + }, + "400.0": { + "key": 400, + "doc_count": 548 + }, + "600.0": { + "key": 600, + "doc_count": 0 + }, + "800.0": { + "key": 800, + "doc_count": 460 + } + } + } + } +} +-------------------------------------------------- + ==== Missing value The `missing` parameter defines how documents that are missing a value should be treated. diff --git a/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc b/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc index bb20b18663e03..ee77d57a0b476 100644 --- a/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc @@ -90,3 +90,93 @@ Response: } } -------------------------------------------------- + +==== Keyed Response + +Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "ip_ranges": { + "ip_range": { + "field": "remote_ip", + "ranges": [ + { "to" : "10.0.0.5" }, + { "from" : "10.0.0.5" } + ], + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "ip_ranges": { + "buckets": { + "*-10.0.0.5": { + "to": "10.0.0.5", + "doc_count": 1462 + }, + "10.0.0.5-*": { + "from": "10.0.0.5", + "doc_count": 50000 + } + } + } + } +} +-------------------------------------------------- + +It is also possible to customize the key for each range: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "ip_ranges": { + "ip_range": { + "field": "remote_ip", + "ranges": [ + { "key": "infinity", "to" : "10.0.0.5" }, + { "key": "and-beyond", "from" : "10.0.0.5" } + ], + "keyed": true + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "ip_ranges": { + "buckets": { + "infinity": { + "to": "10.0.0.5", + "doc_count": 1462 + }, + "and-beyond": { + "from": "10.0.0.5", + "doc_count": 50000 + } + } + } + } +} +-------------------------------------------------- diff --git a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc index db15d0a6a6639..d169dbeb353b0 100644 --- a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc @@ -86,7 +86,52 @@ must be a value between 0-100 inclusive): -------------------------------------------------- <1> Use the `percents` parameter to specify particular percentiles to calculate +==== Keyed Response +By default the `keyed` flag is set to `true` associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Setting the `keyed` flag to `false` will disable this behavior: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "accident_hour_outlier": { + "percentiles": { + "field": "hour_of_day", + "percents" : [80, 85, 95], + "keyed": false + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "accident_hour_outlier": { + "values": [ + { + "key": 80, + "value": 18 + }, + { + "key": 85, + "value": 19 + }, + { + "key": 95, + "value": 22 + } + ] + } + } +} +-------------------------------------------------- ==== Script diff --git a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc index d4df92105defc..9b468b7e50e88 100644 --- a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc @@ -58,6 +58,52 @@ The response will look like this: From this information you can determine you are hitting the 99% load time target but not quite hitting the 95% load time target +==== Keyed Response + +By default the `keyed` flag is set to `true` associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Setting the `keyed` flag to `false` will disable this behavior: + +[source,js] +-------------------------------------------------- +{ + "aggs": { + "accident_hour_outlier": { + "percentile_ranks": { + "field": "hour_of_day", + "values" : [15, 20, 22], + "keyed": false + } + } + } +} +-------------------------------------------------- + +Response: + +[source,js] +-------------------------------------------------- +{ + ... + + "aggregations": { + "accident_hour_outlier": { + "values": [ + { + "key": 15, + "value": 59.80540497209334 + }, + { + "key": 20, + "value": 90.38133124528507 + }, + { + "key": 22, + "value": 97.28720731656692 + } + ] + } + } +} +-------------------------------------------------- ==== Script From 6e33b4159ca10212d931bfd7a6335aeb62eda1c5 Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Tue, 18 Apr 2017 09:47:21 +0530 Subject: [PATCH 2/4] Change examples to allow automated testing Add testable examples using indexes populated in build.gradle - Date Histogram Aggregation - Date Range Aggregation - Percentiles Aggregation - Percentile Ranks Aggregation Remove redundant section `Keyed Response` --- .../bucket/datehistogram-aggregation.asciidoc | 49 +++++++------- .../bucket/daterange-aggregation.asciidoc | 66 ++++++++++++------- .../bucket/histogram-aggregation.asciidoc | 55 ---------------- .../metrics/percentile-aggregation.asciidoc | 48 ++++++++++---- .../percentile-rank-aggregation.asciidoc | 26 ++++---- 5 files changed, 118 insertions(+), 126 deletions(-) diff --git a/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc index 2b900bd9ba2cc..d4d4c9c3d94ea 100644 --- a/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc @@ -308,18 +308,24 @@ Setting the `keyed` flag to `true` will associate a unique string key with each [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { - "aggs": { - "nyc_accident_histogram": { - "date_histogram": { - "field": "date", - "interval" : "year", + "aggs" : { + "sales_over_time" : { + "date_histogram" : { + "field" : "date", + "interval" : "1M", + "format" : "yyyy-MM-dd", "keyed": true } } } } -------------------------------------------------- +// CONSOLE +// TEST[setup:sales] + +Response: Response: @@ -327,35 +333,30 @@ Response: -------------------------------------------------- { ... - "aggregations": { - "nyc_accident_histogram": { + "sales_over_time": { "buckets": { - "2013-01-01T00:00:00.000Z": { - "key_as_string": "2013-01-01T00:00:00.000Z", - "key": 1356998400000, - "doc_count": 203733 - }, - "2014-01-01T00:00:00.000Z": { - "key_as_string": "2014-01-01T00:00:00.000Z", - "key": 1388534400000, - "doc_count": 205929 - }, - "2015-01-01T00:00:00.000Z": { - "key_as_string": "2015-01-01T00:00:00.000Z", + "2015-01-01": { + "key_as_string": "2015-01-01", "key": 1420070400000, - "doc_count": 217637 + "doc_count": 3 + }, + "2015-02-01": { + "key_as_string": "2015-02-01", + "key": 1422748800000, + "doc_count": 2 }, - "2016-01-01T00:00:00.000Z": { - "key_as_string": "2016-01-01T00:00:00.000Z", - "key": 1451606400000, - "doc_count": 227656 + "2015-03-01": { + "key_as_string": "2015-03-01", + "key": 1425168000000, + "doc_count": 2 } } } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] ==== Scripts diff --git a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc index b7d0828d36e71..42c64f23cd335 100644 --- a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc @@ -160,14 +160,16 @@ Setting the `keyed` flag to `true` will associate a unique string key with each [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { - "aggs" : { - "nyc_recent_accidents": { + "aggs": { + "range": { "date_range": { - "field": "@timestamp", + "field": "date", "format": "MM-yyy", "ranges": [ - { "from": "now-10M/d", "to": "now" } + { "to": "now-10M/M" }, + { "from": "now-10M/M" } ], "keyed": true } @@ -175,6 +177,8 @@ Setting the `keyed` flag to `true` will associate a unique string key with each } } -------------------------------------------------- +// CONSOLE +// TEST[setup:sales s/now-10M\/M/10-2015/] Response: @@ -182,35 +186,40 @@ Response: -------------------------------------------------- { ... - "aggregations": { - "nyc_recent_accidents": { + "range": { "buckets": { - "05-2016-03-2017": { - "from": 1464307200000, - "from_as_string": "05-2016", - "to": 1490604059606, - "to_as_string": "03-2017", - "doc_count": 185436 + "*-10-2015": { + "to": 1.4436576E12, + "to_as_string": "10-2015", + "doc_count": 7 + }, + "10-2015-*": { + "from": 1.4436576E12, + "from_as_string": "10-2015", + "doc_count": 0 } } } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] It is also possible to customize the key for each range: [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { - "aggs" : { - "nyc_recent_accidents": { + "aggs": { + "range": { "date_range": { - "field": "@timestamp", + "field": "date", "format": "MM-yyy", "ranges": [ - { "from": "now-10M/d", "to": "now" } + { "from": "01-2015", "to": "03-2015", "key": "quarter_01" }, + { "from": "03-2015", "to": "06-2015", "key": "quarter_02" } ], "keyed": true } @@ -218,6 +227,8 @@ It is also possible to customize the key for each range: } } -------------------------------------------------- +// CONSOLE +// TEST[setup:sales] Response: @@ -225,19 +236,26 @@ Response: -------------------------------------------------- { ... - "aggregations": { - "nyc_recent_accidents": { + "range": { "buckets": { - "last-10M": { - "from": 1464307200000, - "from_as_string": "05-2016", - "to": 1490604059606, - "to_as_string": "03-2017", - "doc_count": 185436 + "quarter_01": { + "from": 1.4200704E12, + "from_as_string": "01-2015", + "to": 1.425168E12, + "to_as_string": "03-2015", + "doc_count": 5 + }, + "quarter_02": { + "from": 1.425168E12, + "from_as_string": "03-2015", + "to": 1.4331168E12, + "to_as_string": "06-2015", + "doc_count": 2 } } } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] diff --git a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc index 4083fd9fe2cb1..de828c62aa9a7 100644 --- a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc @@ -362,61 +362,6 @@ Response: -------------------------------------------------- // TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] -==== Keyed Response - -Setting the `keyed` flag to `true` will associate a unique string key with each bucket and return the ranges as a hash rather than an array: - -[source,js] --------------------------------------------------- -{ - "aggs": { - "bytes_histogram": { - "histogram": { - "field": "bytes", - "interval": 200, - "keyed": true - } - } - } -} --------------------------------------------------- - -Response: - -[source,js] --------------------------------------------------- -{ - ... - - "aggregations": { - "bytes_histogram": { - "buckets": { - "0.0": { - "key": 0, - "doc_count": 13596 - }, - "200.0": { - "key": 200, - "doc_count": 33882 - }, - "400.0": { - "key": 400, - "doc_count": 548 - }, - "600.0": { - "key": 600, - "doc_count": 0 - }, - "800.0": { - "key": 800, - "doc_count": 460 - } - } - } - } -} --------------------------------------------------- - ==== Missing value The `missing` parameter defines how documents that are missing a value should be treated. diff --git a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc index d169dbeb353b0..a9f49aecccf4d 100644 --- a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc @@ -88,22 +88,24 @@ must be a value between 0-100 inclusive): ==== Keyed Response -By default the `keyed` flag is set to `true` associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Setting the `keyed` flag to `false` will disable this behavior: +By default the `keyed` flag is set to `true` which associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Setting the `keyed` flag to `false` will disable this behavior: [source,js] -------------------------------------------------- +POST bank/account/_search?size=0 { "aggs": { - "accident_hour_outlier": { + "balance_outlier": { "percentiles": { - "field": "hour_of_day", - "percents" : [80, 85, 95], + "field": "balance", "keyed": false } } } } -------------------------------------------------- +// CONSOLE +// TEST[setup:bank] Response: @@ -113,25 +115,49 @@ Response: ... "aggregations": { - "accident_hour_outlier": { + "balance_outlier": { "values": [ { - "key": 80, - "value": 18 + "key": 1.0, + "value": 1462.8400000000001 }, { - "key": 85, - "value": 19 + "key": 5.0, + "value": 3591.85 }, { - "key": 95, - "value": 22 + "key": 25.0, + "value": 13709.333333333334 + }, + { + "key": 50.0, + "value": 26020.11666666667 + }, + { + "key": 75.0, + "value": 38139.648148148146 + }, + { + "key": 95.0, + "value": 47551.549999999996 + }, + { + "key": 99.0, + "value": 49339.16 } ] } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] +// TESTRESPONSE[s/1462.8400000000001/$body.aggregations.balance_outlier.values.0.value/] +// TESTRESPONSE[s/3591.85/$body.aggregations.balance_outlier.values.1.value/] +// TESTRESPONSE[s/13709.333333333334/$body.aggregations.balance_outlier.values.2.value/] +// TESTRESPONSE[s/26020.11666666667/$body.aggregations.balance_outlier.values.3.value/] +// TESTRESPONSE[s/38139.648148148146/$body.aggregations.balance_outlier.values.4.value/] +// TESTRESPONSE[s/47551.549999999996/$body.aggregations.balance_outlier.values.5.value/] +// TESTRESPONSE[s/49339.16/$body.aggregations.balance_outlier.values.6.value/] ==== Script diff --git a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc index 9b468b7e50e88..75e8ca35868ee 100644 --- a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc @@ -64,18 +64,21 @@ By default the `keyed` flag is set to `true` associates a unique string key with [source,js] -------------------------------------------------- +POST bank/account/_search?size=0 { "aggs": { - "accident_hour_outlier": { + "balance_outlier": { "percentile_ranks": { - "field": "hour_of_day", - "values" : [15, 20, 22], + "field": "balance", + "values": [25000, 50000], "keyed": false } } } } -------------------------------------------------- +// CONSOLE +// TEST[setup:bank] Response: @@ -85,25 +88,24 @@ Response: ... "aggregations": { - "accident_hour_outlier": { + "balance_outlier": { "values": [ { - "key": 15, - "value": 59.80540497209334 + "key": 25000.0, + "value": 48.537724935732655 }, { - "key": 20, - "value": 90.38133124528507 - }, - { - "key": 22, - "value": 97.28720731656692 + "key": 50000.0, + "value": 99.85567010309278 } ] } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] +// TESTRESPONSE[s/48.537724935732655/$body.aggregations.balance_outlier.values.0.value/] +// TESTRESPONSE[s/99.85567010309278/$body.aggregations.balance_outlier.values.1.value/] ==== Script From edcee39a0eb5c6693abf7e322ea17cd7b7cd5788 Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Tue, 18 Apr 2017 12:15:56 +0530 Subject: [PATCH 3/4] Change Geodistance Agg examples to allow automated testing --- .../bucket/geodistance-aggregation.asciidoc | 96 ++++++++++--------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc b/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc index 7c7e6f4a230d1..c60f8413e462a 100644 --- a/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc @@ -149,17 +149,17 @@ Setting the `keyed` flag to `true` will associate a unique string key with each [source,js] -------------------------------------------------- +POST /museums/_search?size=0 { - "aggs": { - "accidents_near_empire_state": { - "geo_distance": { - "field": "coords", - "unit": "km", - "origin" : { "lat" : 40.7484, "lon" : -73.9857 }, - "ranges": [ - { "to": 3 }, - { "from" : 3, "to" : 8 }, - { "from" : 8 } + "aggs" : { + "rings_around_amsterdam" : { + "geo_distance" : { + "field" : "location", + "origin" : "52.3760, 4.894", + "ranges" : [ + { "to" : 100000 }, + { "from" : 100000, "to" : 300000 }, + { "from" : 300000 } ], "keyed": true } @@ -167,6 +167,8 @@ Setting the `keyed` flag to `true` will associate a unique string key with each } } -------------------------------------------------- +// CONSOLE +// TEST[continued] Response: @@ -174,45 +176,45 @@ Response: -------------------------------------------------- { ... - "aggregations": { - "accidents_near_empire_state": { + "rings_around_amsterdam" : { "buckets": { - "*-3.0": { - "from": 0, - "to": 3, - "doc_count": 102090 + "*-100000.0": { + "from": 0.0, + "to": 100000.0, + "doc_count": 3 }, - "3.0-8.0": { - "from": 3, - "to": 8, - "doc_count": 170287 + "100000.0-300000.0": { + "from": 100000.0, + "to": 300000.0, + "doc_count": 1 }, - "8.0-*": { - "from": 8, - "doc_count": 526590 + "300000.0-*": { + "from": 300000.0, + "doc_count": 2 } } } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/] It is also possible to customize the key for each range: [source,js] -------------------------------------------------- +POST /museums/_search?size=0 { - "aggs": { - "accidents_near_empire_state": { - "geo_distance": { - "field": "coords", - "unit": "km", - "origin" : { "lat" : 40.7484, "lon" : -73.9857 }, - "ranges": [ - { "key": "very-close", "to": 3 }, - { "key": "close", "from" : 3, "to" : 8 }, - { "key": "far", "from" : 8 } + "aggs" : { + "rings_around_amsterdam" : { + "geo_distance" : { + "field" : "location", + "origin" : "52.3760, 4.894", + "ranges" : [ + { "to" : 100000, "key": "first_ring" }, + { "from" : 100000, "to" : 300000, "key": "second_ring" }, + { "from" : 300000, "key": "third_ring" } ], "keyed": true } @@ -220,6 +222,8 @@ It is also possible to customize the key for each range: } } -------------------------------------------------- +// CONSOLE +// TEST[continued] Response: @@ -227,27 +231,27 @@ Response: -------------------------------------------------- { ... - "aggregations": { - "accidents_near_empire_state": { + "rings_around_amsterdam" : { "buckets": { - "very-close": { - "from": 0, - "to": 3, - "doc_count": 102090 + "first_ring": { + "from": 0.0, + "to": 100000.0, + "doc_count": 3 }, - "close": { - "from": 3, - "to": 8, - "doc_count": 170287 + "second_ring": { + "from": 100000.0, + "to": 300000.0, + "doc_count": 1 }, - "far": { - "from": 8, - "doc_count": 526590 + "third_ring": { + "from": 300000.0, + "doc_count": 2 } } } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/] From 8fab6c62fb3857ca903b7fc1a9f5d2f1d69e7ab4 Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Tue, 18 Apr 2017 19:12:25 +0530 Subject: [PATCH 4/4] Remove 'Response:' repetetion in Date Histogram agg --- .../aggregations/bucket/datehistogram-aggregation.asciidoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc index d4d4c9c3d94ea..b7619b175df3d 100644 --- a/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc @@ -327,8 +327,6 @@ POST /sales/_search?size=0 Response: -Response: - [source,js] -------------------------------------------------- {