Skip to content

Commit

Permalink
[DOCS] Add more examples to Painless statements (elastic#48397)
Browse files Browse the repository at this point in the history
Add more examples to the Painless statements documentation (including while and do...while) as requested in elastic#47485 (review)
  • Loading branch information
renshuki authored and jdconrad committed May 11, 2020
1 parent 8e96e5c commit b90c7e3
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions docs/painless/painless-lang-spec/painless-statements.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ control flow statements] except the `switch` statement.
---------------------------------------------------------
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
}
Expand All @@ -21,11 +23,35 @@ if (doc[item].size() == 0) {

===== For

Painless also supports the `for in` syntax from Groovy:
Painless also supports the `for in` syntax:

[source,painless]
---------------------------------------------------------
for (def item : list) {
...
// do something
}
---------------------------------------------------------

[source,painless]
---------------------------------------------------------
for (item in list) {
// do something
}
---------------------------------------------------------

===== While
[source,painless]
---------------------------------------------------------
while (ctx._source.item < condition) {
// do something
}
---------------------------------------------------------

===== Do-While
[source,painless]
---------------------------------------------------------
do {
// do something
}
while (ctx._source.item < condition)
---------------------------------------------------------

0 comments on commit b90c7e3

Please sign in to comment.