From cd0029e1759e173e863167be16b8ecd14615a698 Mon Sep 17 00:00:00 2001 From: renshuki Date: Wed, 23 Oct 2019 22:33:50 +0900 Subject: [PATCH 1/2] Add more examples to Painless statements --- .../painless-statements.asciidoc | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/painless/painless-lang-spec/painless-statements.asciidoc b/docs/painless/painless-lang-spec/painless-statements.asciidoc index b9aceed9cf097..d3c61ac7ba75f 100644 --- a/docs/painless/painless-lang-spec/painless-statements.asciidoc +++ b/docs/painless/painless-lang-spec/painless-statements.asciidoc @@ -6,12 +6,14 @@ control flow statements] except the `switch` statement. ==== Conditional statements -===== If / Else +===== If / Else if / Else [source,painless] --------------------------------------------------------- if (doc[item].size() == 0) { // do something if "item" is missing +} else if (doc[item].value == 'something') { + // do something if "item" value is: something } else { // do something else } @@ -26,6 +28,23 @@ Painless also supports the `for in` syntax from Groovy: [source,painless] --------------------------------------------------------- for (item : list) { - ... + // do something } --------------------------------------------------------- + +===== While +[source,painless] +--------------------------------------------------------- +while (ctx._source.item < condition) { + // do something +} +--------------------------------------------------------- + +===== Do...While +[source,painless] +--------------------------------------------------------- +do { + // something +} +while (ctx._source.item < condition) +--------------------------------------------------------- From 6eba8bfc5887c2de3a1902805c517697a0b1ba8f Mon Sep 17 00:00:00 2001 From: renshuki Date: Thu, 12 Dec 2019 19:31:09 +0900 Subject: [PATCH 2/2] Update titles for Painless statements doc --- docs/painless/painless-lang-spec/painless-statements.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/painless/painless-lang-spec/painless-statements.asciidoc b/docs/painless/painless-lang-spec/painless-statements.asciidoc index d3c61ac7ba75f..0c4e6bcd976c6 100644 --- a/docs/painless/painless-lang-spec/painless-statements.asciidoc +++ b/docs/painless/painless-lang-spec/painless-statements.asciidoc @@ -6,7 +6,7 @@ control flow statements] except the `switch` statement. ==== Conditional statements -===== If / Else if / Else +===== If / Else [source,painless] --------------------------------------------------------- @@ -40,7 +40,7 @@ while (ctx._source.item < condition) { } --------------------------------------------------------- -===== Do...While +===== Do-While [source,painless] --------------------------------------------------------- do {