mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-22 21:05:23 +00:00
[DOCS] Add more examples to Painless statements (#48397)
Add more examples to the Painless statements documentation (including while and do...while) as requested in #47485 (review)
This commit is contained in:
parent
8e96e5c936
commit
b90c7e3797
@ -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
|
||||
}
|
||||
@ -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)
|
||||
---------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user