From 40e26451778722596bf48994a2288c7213f90f8e Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 22 Jan 2017 23:36:53 -0500 Subject: [PATCH] CONSOLE-ify date_range aggregation docs This adds the `VIEW IN CONSOLE` and `COPY AS CURL` links to the snippets in the docs for the `date_range` aggregation and tests those snippets as part of the build. Relates to #18160 --- docs/build.gradle | 1 - .../bucket/daterange-aggregation.asciidoc | 46 +++++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 29a4f9430da..c4346018c1a 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -24,7 +24,6 @@ apply plugin: 'elasticsearch.docs-test' * only remove entries from this list. When it is empty we'll remove it * entirely and have a party! There will be cake and everything.... */ buildRestTests.expectedUnconvertedCandidates = [ - 'reference/aggregations/bucket/daterange-aggregation.asciidoc', 'reference/aggregations/bucket/diversified-sampler-aggregation.asciidoc', 'reference/aggregations/bucket/filter-aggregation.asciidoc', 'reference/aggregations/bucket/geodistance-aggregation.asciidoc', diff --git a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc index a69b2b3cb11..df32075583f 100644 --- a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc @@ -8,6 +8,7 @@ Example: [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { "aggs": { "range": { @@ -23,6 +24,9 @@ Example: } } -------------------------------------------------- +// CONSOLE +// TEST[setup:sales s/now-10M\/M/10-2015/] + <1> < now minus 10 months, rounded down to the start of the month. <2> >= now minus 10 months, rounded down to the start of the month. @@ -35,25 +39,27 @@ Response: -------------------------------------------------- { ... - "aggregations": { "range": { "buckets": [ { - "to": 1.3437792E+12, - "to_as_string": "08-2012", - "doc_count": 7 + "to": 1.4436576E12, + "to_as_string": "10-2015", + "doc_count": 7, + "key": "*-10-2015" }, { - "from": 1.3437792E+12, - "from_as_string": "08-2012", - "doc_count": 2 + "from": 1.4436576E12, + "from_as_string": "10-2015", + "doc_count": 0, + "key": "10-2015-*" } ] } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] [[date-format-pattern]] ==== Date Format/Pattern @@ -125,21 +131,25 @@ to round to the beginning of the day in the CET time zone, you can do the follow [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { "aggs": { - "range": { - "date_range": { - "field": "date", - "time_zone": "CET", - "ranges": [ - { "to": "2016-02-15/d" }, <1> - { "from": "2016-02-15/d", "to" : "now/d" <2>}, - { "from": "now/d" }, - ] - } + "range": { + "date_range": { + "field": "date", + "time_zone": "CET", + "ranges": [ + { "to": "2016/02/01" }, <1> + { "from": "2016/02/01", "to" : "now/d" <2>}, + { "from": "now/d" } + ] } } - } + } +} -------------------------------------------------- +// CONSOLE +// TEST[setup:sales] + <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.