From bbe93fe2f762268ebe73263ff41fc4af6781ff0c Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Tue, 26 Jan 2021 15:33:41 -0500 Subject: [PATCH 01/12] Adds datetime as a date, which is necessary in setup. --- docs/build.gradle | 2 ++ .../painless-contexts/painless-context-examples.asciidoc | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/build.gradle b/docs/build.gradle index adebfdcfa4047..ae75bce2b876c 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -1333,6 +1333,8 @@ setups['seats'] = ''' type: long sold: type: boolean + datetime: + type: date - do: raw: diff --git a/docs/painless/painless-contexts/painless-context-examples.asciidoc b/docs/painless/painless-contexts/painless-context-examples.asciidoc index c00e1cf07d250..15859561e990a 100644 --- a/docs/painless/painless-contexts/painless-context-examples.asciidoc +++ b/docs/painless/painless-contexts/painless-context-examples.asciidoc @@ -24,6 +24,8 @@ Each document in the `seat` data contains the following fields: The number of the seat within a row. `sold` ({ref}/boolean.html[`boolean`]):: Whether or not the seat is sold. +`datetime` ({ref}/date.html[`date`]):: + The date and time of the play as a date object. ==== Prerequisites Start an {ref}/getting-started-install.html[{es} instance], and then access the @@ -47,7 +49,8 @@ PUT /seats "cost": { "type": "double" }, "row": { "type": "integer" }, "number": { "type": "integer" }, - "sold": { "type": "boolean" } + "sold": { "type": "boolean" }, + "datetime": { "type": "date" } } } } From cabd9ec3859beb1e13d9e1a951802b4d88080106 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Tue, 26 Jan 2021 16:05:19 -0500 Subject: [PATCH 02/12] Updating field context example. --- .../painless-contexts/painless-field-context.asciidoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/painless/painless-contexts/painless-field-context.asciidoc b/docs/painless/painless-contexts/painless-field-context.asciidoc index b2dc804721cac..e786de8f6f11e 100644 --- a/docs/painless/painless-contexts/painless-field-context.asciidoc +++ b/docs/painless/painless-contexts/painless-field-context.asciidoc @@ -70,15 +70,15 @@ GET seats/_search "script_fields": { "day-of-week": { "script": { - "source": "doc['datetime'].value.getDayOfWeek()" + "source": "doc['datetime'].value.getDayOfWeekEnum()" } }, "number-of-actors": { "script": { - "source": "params['_source']['actors'].length" + "source": "params['_source']['actors']" } } } } ---- -// TEST[skip: requires setup from other pages] \ No newline at end of file +// TEST[setup:seats] From 25e733ae236ea7c6541779916949ba0d25bfbb22 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Tue, 26 Jan 2021 17:37:09 -0500 Subject: [PATCH 03/12] Fixing sample data, updating context example, and updating runtime example. --- docs/build.gradle | 7 +-- .../painless-field-context.asciidoc | 2 +- .../painless-runtime-fields-context.asciidoc | 47 +++++++++++-------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index ae75bce2b876c..67d58231adfb5 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -1320,7 +1320,7 @@ setups['seats'] = ''' play: type: keyword actors: - type: keyword + type: text date: type: keyword time: @@ -1354,14 +1354,15 @@ setups['seats'] = ''' - do: bulk: index: seats + pipeline: seats refresh: true body: | {"index":{"_id": "1"}} {"theatre": "Skyline", "play": "Rent", "actors": ["James Holland", "Krissy Smith", "Joe Muir", "Ryan Earns"], "date": "2021-4-1", "time": "3:00PM", "cost": 37, "row": 1, "number": 7, "sold": false} {"index":{"_id": "2"}} - {"theatre": "Graye", "play": "Rent", "actors": "Dave Christmas", "date": "2021-4-1", "time": "3:00PM", "cost": 30, "row": 3, "number": 5, "sold": false} + {"theatre": "Graye", "play": "Rent", "actors": ["Dave Christmas"], "date": "2021-4-1", "time": "3:00PM", "cost": 30, "row": 3, "number": 5, "sold": false} {"index":{"_id": "3"}} - {"theatre": "Graye", "play": "Rented", "actors": "Dave Christmas", "date": "2021-4-1", "time": "3:00PM", "cost": 33, "row": 2, "number": 6, "sold": false} + {"theatre": "Graye", "play": "Rented", "actors": ["Dave Christmas"], "date": "2021-4-1", "time": "3:00PM", "cost": 33, "row": 2, "number": 6, "sold": false} {"index":{"_id": "4"}} {"theatre": "Skyline", "play": "Rented", "actors": ["James Holland", "Krissy Smith", "Joe Muir", "Ryan Earns"], "date": "2021-4-1", "time": "3:00PM", "cost": 20, "row": 5, "number": 2, "sold": false} {"index":{"_id": "5"}} diff --git a/docs/painless/painless-contexts/painless-field-context.asciidoc b/docs/painless/painless-contexts/painless-field-context.asciidoc index e786de8f6f11e..dba2a9e033e69 100644 --- a/docs/painless/painless-contexts/painless-field-context.asciidoc +++ b/docs/painless/painless-contexts/painless-field-context.asciidoc @@ -75,7 +75,7 @@ GET seats/_search }, "number-of-actors": { "script": { - "source": "params['_source']['actors']" + "source": "params['_source']['actors'].size()" } } } diff --git a/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc b/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc index 4bc43940ba94a..6cc1e9b473367 100644 --- a/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc +++ b/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc @@ -92,28 +92,25 @@ can ingest the full https://download.elastic.co/demos/painless/contexts/seats.js ---- POST seats/_bulk?pipeline=seats&refresh=true {"create":{"_index":"seats","_id":"1"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":1,"cost":30,"sold":false} +{"theatre":"Skyline","play":"Rent","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2021-4-1","time":"3:00PM","cost":37,"row":1,"number":7,"sold":false} {"create":{"_index":"seats","_id":"2"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":2,"cost":30,"sold":false} +{"theatre":"Graye","play":"Rent","actors":["Dave Christmas"],"date":"2021-4-1","time":"3:00PM","cost":30,"row":3,"number":5,"sold":false} {"create":{"_index":"seats","_id":"3"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":3,"cost":30,"sold":true} +{"theatre":"Graye","play":"Rented","actors":["Dave Christmas"],"date":"2021-4-1","time":"3:00PM","cost":33,"row":2,"number":6,"sold":false} {"create":{"_index":"seats","_id":"4"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":4,"cost":30,"sold":false} +{"theatre":"Skyline","play":"Rented","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2021-4-1","time":"3:00PM","cost":20,"row":5,"number":2,"sold":false} {"create":{"_index":"seats","_id":"5"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":5,"cost":30,"sold":false} +{"theatre":"Down Port","play":"Pick It Up","actors":["Joel Madigan","Jessica Brown","Baz Knight","Jo Hangum","Rachel Grass","Phoebe Miller"],"date":"2018-4-2","time":"8:00PM","cost":27.5,"row":3,"number":2,"sold":false} {"create":{"_index":"seats","_id":"6"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":6,"cost":30,"sold":true} +{"theatre":"Down Port","play":"Harriot","actors":["Phoebe Miller","Sarah Notch","Brayden Green","Joshua Iller","Jon Hittle","Rob Kettleman","Laura Conrad","Simon Hower","Nora Blue","Mike Candlestick","Jacey Bell"],"date":"2018-8-7","time":"8:00PM","cost":30,"row":1,"number":10,"sold":false} {"create":{"_index":"seats","_id":"7"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":7,"cost":30,"sold":true} +{"theatre":"Skyline","play":"Auntie Jo","actors":["Jo Hangum","Jon Hittle","Rob Kettleman","Laura Conrad","Simon Hower","Nora Blue"],"date":"2018-10-2","time":"5:40PM","cost":22.5,"row":7,"number":10,"sold":false} {"create":{"_index":"seats","_id":"8"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":8,"cost":30,"sold":false} +{"theatre":"Skyline","play":"Test Run","actors":["Joe Muir","Ryan Earns","Joel Madigan","Jessica Brown"],"date":"2018-8-5","time":"7:30PM","cost":17.5,"row":11,"number":12,"sold":true} {"create":{"_index":"seats","_id":"9"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":9,"cost":30,"sold":true} +{"theatre":"Skyline","play":"Sunnyside Down","actors":["Krissy Smith","Joe Muir","Ryan Earns","Nora Blue","Mike Candlestick","Jacey Bell"],"date":"2018-6-12","time":"4:00PM","cost":21.25,"row":8,"number":15,"sold":true} {"create":{"_index":"seats","_id":"10"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":10,"cost":30,"sold":false} -{"create":{"_index":"seats","_id":"11"}} -{"theatre":"Down Port","play":"Driving","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2018-4-1","time":"3:00PM","row":1,"number":11,"cost":30,"sold":false} -{"create":{"_index":"seats","_id":"12"}} +{"theatre":"Graye","play":"Line and Single","actors":["Nora Blue","Mike Candlestick"],"date":"2018-6-5","time":"2:00PM","cost":30,"row":1,"number":2,"sold":false} ---- // TEST[continued] @@ -133,9 +130,9 @@ PUT seats/_mapping { "runtime": { "day_of_week": { - "type": "date", + "type": "keyword", "script": { - "source": "emit(doc['datetime'].value.getDayOfWeekEnum().getValue())" + "source": "emit(doc['datetime'].value.getDayOfWeekEnum().toString())" } } } @@ -179,7 +176,7 @@ defined in the mappings. ... "hits" : { "total" : { - "value" : 11, + "value" : 10, "relation" : "eq" }, "max_score" : null, @@ -191,9 +188,20 @@ defined in the mappings. "sum_other_doc_count" : 0, "buckets" : [ { - "key" : 7, - "key_as_string" : "1970-01-01T00:00:00.007Z", - "doc_count" : 11 + "key" : "THURSDAY", + "doc_count" : 4 + }, + { + "key" : "TUESDAY", + "doc_count" : 4 + }, + { + "key" : "MONDAY", + "doc_count" : 1 + }, + { + "key" : "SUNDAY", + "doc_count" : 1 } ] } @@ -201,4 +209,3 @@ defined in the mappings. } ---- // TESTRESPONSE[s/\.\.\./"took" : $body.took,"timed_out" : $body.timed_out,"_shards" : $body._shards,/] -// TESTRESPONSE[s/"value" : "11"/"value": $body.hits.total.value/] From bfedf2cd77864943914a997e4db4e25bc409abf8 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Tue, 26 Jan 2021 17:59:47 -0500 Subject: [PATCH 04/12] Updating field context and changing runtime field to use seats data. --- .../painless-field-context.asciidoc | 4 +- .../painless-runtime-fields-context.asciidoc | 90 ++----------------- 2 files changed, 7 insertions(+), 87 deletions(-) diff --git a/docs/painless/painless-contexts/painless-field-context.asciidoc b/docs/painless/painless-contexts/painless-field-context.asciidoc index dba2a9e033e69..4ca1ecf572433 100644 --- a/docs/painless/painless-contexts/painless-field-context.asciidoc +++ b/docs/painless/painless-contexts/painless-field-context.asciidoc @@ -42,7 +42,7 @@ the `getDayOfWeek` function to determine the corresponding day of the week. [source,Painless] ---- -doc['datetime'].value.getDayOfWeek(); +doc['datetime'].value.getDayOfWeekEnum(); ---- The second script calculates the number of actors. Actors' names are stored @@ -50,7 +50,7 @@ as a text array in the `actors` field. [source,Painless] ---- -params['_source']['actors'].length; <1> +params['_source']['actors'].size(); <1> ---- <1> By default, doc values are not available for text fields. However, diff --git a/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc b/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc index 6cc1e9b473367..60c13166514ab 100644 --- a/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc +++ b/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc @@ -33,91 +33,11 @@ Both the standard <> and *Example* -Let's break down each of the steps from the -<> to understand how runtime fields -work within the context of Painless. +To run this example, first follow the steps in +<>. -[[painless-runtime-fields-mappings]] -==== Create the index mappings -First, create the mappings for the sample data: - -[source,console] ----- -PUT /seats -{ - "mappings": { - "properties": { - "theatre": { "type": "keyword" }, - "play": { "type": "keyword" }, - "actors": { "type": "text" }, - "row": { "type": "integer" }, - "number": { "type": "integer" }, - "cost": { "type": "double" }, - "sold": { "type": "boolean" }, - "datetime": { "type": "date" }, - "date": { "type": "keyword" }, - "time": { "type": "keyword" } - } - } -} ----- - -[[painless-runtime-fields-processor]] -==== Run the ingest processor -Next, run the request from the <> to configure a script ingest processor that parses -each document as the `seat` data is indexed: - -[source,console] ----- -PUT /_ingest/pipeline/seats -{ - "description": "update datetime for seats", - "processors": [ - { - "script": { - "source": "String[] dateSplit = ctx.date.splitOnToken('-'); String year = dateSplit[0].trim(); String month = dateSplit[1].trim(); if (month.length() == 1) { month = '0' + month; } String day = dateSplit[2].trim(); if (day.length() == 1) { day = '0' + day; } boolean pm = ctx.time.substring(ctx.time.length() - 2).equals('PM'); String[] timeSplit = ctx.time.substring(0, ctx.time.length() - 2).splitOnToken(':'); int hours = Integer.parseInt(timeSplit[0].trim()); int minutes = Integer.parseInt(timeSplit[1].trim()); if (pm) { hours += 12; } String dts = year + '-' + month + '-' + day + 'T' + (hours < 10 ? '0' + hours : '' + hours) + ':' + (minutes < 10 ? '0' + minutes : '' + minutes) + ':00+08:00'; ZonedDateTime dt = ZonedDateTime.parse(dts, DateTimeFormatter.ISO_OFFSET_DATE_TIME); ctx.datetime = dt.getLong(ChronoField.INSTANT_SECONDS)*1000L;" - } - } - ] -} ----- -// TEST[continued] - -[[painless-runtime-fields-ingest]] -==== Ingest some sample data -Use the ingest pipeline you defined to ingest some sample data. You -can ingest the full https://download.elastic.co/demos/painless/contexts/seats.json[seat sample data], but we'll only use a subset for this example: - -[source,console] ----- -POST seats/_bulk?pipeline=seats&refresh=true -{"create":{"_index":"seats","_id":"1"}} -{"theatre":"Skyline","play":"Rent","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2021-4-1","time":"3:00PM","cost":37,"row":1,"number":7,"sold":false} -{"create":{"_index":"seats","_id":"2"}} -{"theatre":"Graye","play":"Rent","actors":["Dave Christmas"],"date":"2021-4-1","time":"3:00PM","cost":30,"row":3,"number":5,"sold":false} -{"create":{"_index":"seats","_id":"3"}} -{"theatre":"Graye","play":"Rented","actors":["Dave Christmas"],"date":"2021-4-1","time":"3:00PM","cost":33,"row":2,"number":6,"sold":false} -{"create":{"_index":"seats","_id":"4"}} -{"theatre":"Skyline","play":"Rented","actors":["James Holland","Krissy Smith","Joe Muir","Ryan Earns"],"date":"2021-4-1","time":"3:00PM","cost":20,"row":5,"number":2,"sold":false} -{"create":{"_index":"seats","_id":"5"}} -{"theatre":"Down Port","play":"Pick It Up","actors":["Joel Madigan","Jessica Brown","Baz Knight","Jo Hangum","Rachel Grass","Phoebe Miller"],"date":"2018-4-2","time":"8:00PM","cost":27.5,"row":3,"number":2,"sold":false} -{"create":{"_index":"seats","_id":"6"}} -{"theatre":"Down Port","play":"Harriot","actors":["Phoebe Miller","Sarah Notch","Brayden Green","Joshua Iller","Jon Hittle","Rob Kettleman","Laura Conrad","Simon Hower","Nora Blue","Mike Candlestick","Jacey Bell"],"date":"2018-8-7","time":"8:00PM","cost":30,"row":1,"number":10,"sold":false} -{"create":{"_index":"seats","_id":"7"}} -{"theatre":"Skyline","play":"Auntie Jo","actors":["Jo Hangum","Jon Hittle","Rob Kettleman","Laura Conrad","Simon Hower","Nora Blue"],"date":"2018-10-2","time":"5:40PM","cost":22.5,"row":7,"number":10,"sold":false} -{"create":{"_index":"seats","_id":"8"}} -{"theatre":"Skyline","play":"Test Run","actors":["Joe Muir","Ryan Earns","Joel Madigan","Jessica Brown"],"date":"2018-8-5","time":"7:30PM","cost":17.5,"row":11,"number":12,"sold":true} -{"create":{"_index":"seats","_id":"9"}} -{"theatre":"Skyline","play":"Sunnyside Down","actors":["Krissy Smith","Joe Muir","Ryan Earns","Nora Blue","Mike Candlestick","Jacey Bell"],"date":"2018-6-12","time":"4:00PM","cost":21.25,"row":8,"number":15,"sold":true} -{"create":{"_index":"seats","_id":"10"}} -{"theatre":"Graye","play":"Line and Single","actors":["Nora Blue","Mike Candlestick"],"date":"2018-6-5","time":"2:00PM","cost":30,"row":1,"number":2,"sold":false} ----- -// TEST[continued] - -[[painless-runtime-fields-definition]] -==== Define a runtime field with a Painless script -Run the following request to define a runtime field named `day_of_week`. This -field contains a script with the same `source` defined in +Then, run the following request to define a runtime field named `day_of_week`. +This field contains a script with the same `source` defined in <>, but also uses an `emit` function that runtime fields require when defining a Painless script. @@ -138,7 +58,7 @@ PUT seats/_mapping } } ---- -// TEST[continued] +// TEST[setup:seats] After defining the runtime field and script in the mappings, you can run a query that includes a terms aggregation for `day_of_week`. When the query runs, From 7e20388eca7fc0e6c83f13ea8cfa47f653f4b71f Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Tue, 26 Jan 2021 18:05:25 -0500 Subject: [PATCH 05/12] Update filter context to use the seats data. --- .../painless-filter-context.asciidoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/painless/painless-contexts/painless-filter-context.asciidoc b/docs/painless/painless-contexts/painless-filter-context.asciidoc index 3956c67411ee5..488a621991c89 100644 --- a/docs/painless/painless-contexts/painless-filter-context.asciidoc +++ b/docs/painless/painless-contexts/painless-filter-context.asciidoc @@ -30,16 +30,16 @@ The standard <> is available. To run this example, first follow the steps in <>. -This script finds all unsold documents that cost less than $18. +This script finds all unsold documents that cost less than $25. [source,Painless] ---- -doc['sold'].value == false && doc['cost'].value < 18 +doc['sold'].value == false && doc['cost'].value < 25 ---- -Defining cost as a script parameter enables the cost to be configured +Defining `cost` as a script parameter enables the cost to be configured in the script query request. For example, the following request finds -all available theatre seats for evening performances that are under $18. +all available theatre seats for evening performances that are under $25. [source,console] ---- @@ -52,7 +52,7 @@ GET seats/_search "script": { "source": "doc['sold'].value == false && doc['cost'].value < params.cost", "params": { - "cost": 18 + "cost": 25 } } } @@ -61,4 +61,4 @@ GET seats/_search } } ---- -// TEST[skip: requires setup from other pages] \ No newline at end of file +// TEST[setup:seats] From 82db163e18e5de87142af26b3c34fb5b40f6df41 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Tue, 26 Jan 2021 18:10:55 -0500 Subject: [PATCH 06/12] Updating min-should-match context to use seats data. --- .../painless-min-should-match-context.asciidoc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/painless/painless-contexts/painless-min-should-match-context.asciidoc b/docs/painless/painless-contexts/painless-min-should-match-context.asciidoc index 7d118cf6fa8c2..9d1c70b5bc95a 100644 --- a/docs/painless/painless-contexts/painless-min-should-match-context.asciidoc +++ b/docs/painless/painless-contexts/painless-min-should-match-context.asciidoc @@ -35,12 +35,14 @@ To run this example, first follow the steps in Imagine that you want to find seats to performances by your favorite actors. You have a list of favorite actors in mind, and you want to find performances where the cast includes at least a certain -number of them. `terms_set` query with `minimum_should_match_script` -is a way to accomplish this. To make the query request more configurable, +number of them. + +To achieve this result, use a `terms_set` query with +`minimum_should_match_script`. To make the query request more configurable, you can define `min_actors_to_see` as a script parameter. To ensure that the parameter `min_actors_to_see` doesn't exceed -the number of favorite actors, you can use `num_term`s to get +the number of favorite actors, you can use `num_terms` to get the number of actors in the list and `Math.min` to get the lesser of the two. @@ -75,5 +77,4 @@ GET seats/_search } } ---- -// TEST[skip: requires setup from other pages] - +// TEST[setup:seats] From 5bd8a0342fb71dc3fae4217c790f0255f5790445 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Wed, 27 Jan 2021 09:05:33 -0500 Subject: [PATCH 07/12] Replacing last mentions of TEST[skip]. --- .../painless-runtime-fields-context.asciidoc | 2 +- .../painless-watcher-condition-context.asciidoc | 7 +++++-- .../painless-watcher-context-example.asciidoc | 4 ++-- .../painless-watcher-context-variables.asciidoc | 7 ------- .../painless-watcher-transform-context.asciidoc | 7 +++++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc b/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc index 60c13166514ab..855d8e269eb3d 100644 --- a/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc +++ b/docs/painless/painless-contexts/painless-runtime-fields-context.asciidoc @@ -33,7 +33,7 @@ Both the standard <> and *Example* -To run this example, first follow the steps in +To run the examples, first follow the steps in <>. Then, run the following request to define a runtime field named `day_of_week`. diff --git a/docs/painless/painless-contexts/painless-watcher-condition-context.asciidoc b/docs/painless/painless-contexts/painless-watcher-condition-context.asciidoc index bb10b534cc98d..f973ad4980bc8 100644 --- a/docs/painless/painless-contexts/painless-watcher-condition-context.asciidoc +++ b/docs/painless/painless-contexts/painless-watcher-condition-context.asciidoc @@ -18,6 +18,9 @@ The standard <> is available. *Example* +To run the examples, first follow the steps in +<>. + [source,console] ---- POST _watcher/watch/_execute @@ -65,7 +68,7 @@ POST _watcher/watch/_execute } } ---- -// TEST[skip: requires setup from other pages] +// TEST[setup:seats] <1> The Java Stream API is used in the condition. This API allows manipulation of the elements of the list in a pipeline. @@ -122,7 +125,7 @@ POST _watcher/watch/_execute } } ---- -// TEST[skip: requires setup from other pages] +// TEST[setup:seats] This example uses a nearly identical condition as the previous example. The differences below are subtle and are worth calling out. diff --git a/docs/painless/painless-contexts/painless-watcher-context-example.asciidoc b/docs/painless/painless-contexts/painless-watcher-context-example.asciidoc index db1394416b6bd..1c161479aec3a 100644 --- a/docs/painless/painless-contexts/painless-watcher-context-example.asciidoc +++ b/docs/painless/painless-contexts/painless-watcher-context-example.asciidoc @@ -99,7 +99,7 @@ POST _watcher/watch/_execute } } ---- -// TEST[skip: requires setup from other pages] +// TEST[setup:seats] The following example shows the use of metadata and transforming dates into a readable format. @@ -156,4 +156,4 @@ POST _watcher/watch/_execute } } ---- -// TEST[skip: requires setup from other pages] \ No newline at end of file +// TEST[setup:seats] diff --git a/docs/painless/painless-contexts/painless-watcher-context-variables.asciidoc b/docs/painless/painless-contexts/painless-watcher-context-variables.asciidoc index 44b75fa205f0f..0a21ae1fd2bdc 100644 --- a/docs/painless/painless-contexts/painless-watcher-context-variables.asciidoc +++ b/docs/painless/painless-contexts/painless-watcher-context-variables.asciidoc @@ -30,10 +30,3 @@ The following variables are available in all watcher contexts. `ctx['payload']` (`Map`, read-only):: The accessible watch data based upon the {ref}/input.html[watch input]. - -*API* - -The standard <> is available. - -To run this example, first follow the steps in -<>. diff --git a/docs/painless/painless-contexts/painless-watcher-transform-context.asciidoc b/docs/painless/painless-contexts/painless-watcher-transform-context.asciidoc index 59b03ddc4a1ac..3b67161f0f61d 100644 --- a/docs/painless/painless-contexts/painless-watcher-transform-context.asciidoc +++ b/docs/painless/painless-contexts/painless-watcher-transform-context.asciidoc @@ -18,6 +18,9 @@ The standard <> is available. *Example* +To run the examples, first follow the steps in +<>. + [source,console] ---- POST _watcher/watch/_execute @@ -75,7 +78,7 @@ POST _watcher/watch/_execute } } ---- -// TEST[skip: requires setup from other pages] +// TEST[setup:seats] <1> The Java Stream API is used in the transform. This API allows manipulation of the elements of the list in a pipeline. @@ -141,7 +144,7 @@ POST _watcher/watch/_execute } } ---- -// TEST[skip: requires setup from other pages] +// TEST[setup:seats] This example uses the streaming API in a very similar manner. The differences below are subtle and worth calling out. From 059cbc963b583cbfe55bc121b58ea9739fce0c89 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Wed, 27 Jan 2021 11:36:26 -0500 Subject: [PATCH 08/12] Update usage with watcher response for build error. --- docs/reference/rest-api/usage.asciidoc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index 27d29d6949a4e..133c696cb7989 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -59,11 +59,19 @@ GET /_xpack/usage "watcher" : { "available" : true, "enabled" : true, + "count" : { + "active" : 0, + "total" : 0 + }, "execution" : { "actions" : { + "logging" : { + "total" : 6, + "total_time_in_ms" : 70 + }, "_all" : { - "total" : 0, - "total_time_in_ms" : 0 + "total" : 6, + "total_time_in_ms" : 271 } } }, From 78c89ed196a63d394bdd963b14e4802762431dcd Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Wed, 27 Jan 2021 12:30:30 -0500 Subject: [PATCH 09/12] Updating usage API again for watcher. --- docs/reference/rest-api/usage.asciidoc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index 68c6bf0e47a1b..5126784548113 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -11,13 +11,6 @@ Provides usage information about the installed {xpack} features. `GET /_xpack/usage` -[discrete] -[[usage-api-prereqs]] -=== {api-prereq-title} - -* If the {es} {security-features} are enabled, you must have the `monitor` or -`manage` <> to use this API. - [discrete] [[usage-api-desc]] === {api-description-title} @@ -73,12 +66,12 @@ GET /_xpack/usage "execution" : { "actions" : { "logging" : { - "total" : 6, - "total_time_in_ms" : 70 + "total" : 0, + "total_time_in_ms" : 0 }, "_all" : { - "total" : 6, - "total_time_in_ms" : 271 + "total" : 0, + "total_time_in_ms" : 0 } } }, From fdb301176df98b102c79f842a7dede49c82b7092 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Wed, 27 Jan 2021 14:15:29 -0500 Subject: [PATCH 10/12] Third time's a charm for fixing test cases. --- docs/reference/rest-api/usage.asciidoc | 37 ++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index 5126784548113..e5f3938513aca 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -11,6 +11,13 @@ Provides usage information about the installed {xpack} features. `GET /_xpack/usage` +[discrete] +[[usage-api-prereqs]] +=== {api-prereq-title} + +* If the {es} {security-features} are enabled, you must have the `monitor` or +`manage` <> to use this API. + [discrete] [[usage-api-desc]] === {api-description-title} @@ -57,24 +64,20 @@ GET /_xpack/usage } }, "watcher" : { - "available" : true, - "enabled" : true, - "count" : { - "active" : 0, - "total" : 0 - }, - "execution" : { - "actions" : { - "logging" : { - "total" : 0, - "total_time_in_ms" : 0 - }, - "_all" : { - "total" : 0, - "total_time_in_ms" : 0 + "available" : true, + "enabled" : true, + "execution" : { + "actions" : { + "logging" : { + "total" : 0, + "total_time_in_ms" : 0 + }, + "_all" : { + "total" : 0, + "total_time_in_ms" : 0 + } } - } - }, + }, "watch" : { "input" : { "_all" : { From 7295e39da864d3dbc7581b606151a2d4b93bd5b4 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Wed, 27 Jan 2021 14:50:40 -0500 Subject: [PATCH 11/12] Adding specific test replacement for watcher logging total. --- docs/reference/rest-api/usage.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index e5f3938513aca..e65e27dcff9a0 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -368,6 +368,7 @@ GET /_xpack/usage // TESTRESPONSE[s/ : true/ : $body.$_path/] // TESTRESPONSE[s/ : false/ : $body.$_path/] // TESTRESPONSE[s/ : (\-)?[0-9]+/ : $body.$_path/] +// TESTRESPONSE[s/"total" : 0/"total" : $body.watcher.execution.actions.logging.total/] // These replacements do a few things: // 1. Ignore the contents of the `policy_stats` object because we don't know all // of the policies that will be in it. And because we figure folks don't need From 6da8ea08b513d1a5ad2ffde5c51213a17942c2d2 Mon Sep 17 00:00:00 2001 From: Adam Locke Date: Wed, 27 Jan 2021 16:19:40 -0500 Subject: [PATCH 12/12] Change actors to keyword based on review feedback. --- docs/build.gradle | 2 +- .../painless-contexts/painless-context-examples.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 67d58231adfb5..c725ad5acc55f 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -1320,7 +1320,7 @@ setups['seats'] = ''' play: type: keyword actors: - type: text + type: keyword date: type: keyword time: diff --git a/docs/painless/painless-contexts/painless-context-examples.asciidoc b/docs/painless/painless-contexts/painless-context-examples.asciidoc index 15859561e990a..407f5b5c9c9e2 100644 --- a/docs/painless/painless-contexts/painless-context-examples.asciidoc +++ b/docs/painless/painless-contexts/painless-context-examples.asciidoc @@ -43,7 +43,7 @@ PUT /seats "properties": { "theatre": { "type": "keyword" }, "play": { "type": "keyword" }, - "actors": { "type": "text" }, + "actors": { "type": "keyword" }, "date": { "type": "keyword" }, "time": { "type": "keyword" }, "cost": { "type": "double" },