We state that painless is similar than Groovy, but to be fair most of the code that you paste from groovy will need to be modified in order to work with this new language.
One simple example is the following that works in Groovy but not in Painless:
variable = list.sort { a, b -> a.value == b.value ? 0 : a.value < b.value ? -1 : 1 }
Now, this could be translated into the following:
variable = list.sort( (a, b) -> a.value == b.value ? 0 : a.value < b.value ? -1 : 1 );
Also, looks like joda.time.DateTime cannot be used, and there is no clear explanation how to deal with dates. See https://github.com/elastic/elasticsearch/issues/22162.
As you can see, it's similar, but still you usually need to modify a big part of the code. Unfortunately this type of similarities are not documented, nor you can understand in an easy way how to translate groovy or how to develop with painless. My proposal is to:
We shouldn't expect to have a large documentation, but at least to have the general concepts. Just to see how other languages are explained:
We state that painless is similar than Groovy, but to be fair most of the code that you paste from groovy will need to be modified in order to work with this new language.
To be fair, when developers hear that two languages are similar, they do not have an expectation that they can paste code from one language into another. For example, developers freely admit that C# and Java are similar (in fact, very similar), but no developer comfortable with one of those languages expects they can paste code back and forth between the two (sometimes you can paste a snippet, the vast majority of the time you can not).
This does not negate the point that we should always work to improve our documentation, especially for a feature as nascent as Painless is, but I do think it's worth correcting the expectation that developers have when they say and hear that two languages are similar.
Agree 100% the documentation needs improvements. I'm currently working on making some, but there's a lot to cover and it's going to take some time to get there. I also see how comparing this language to Groovy could be confusing given the lack of documentation here.
I'm still working on prerequisites for an API reference.... I think I have one review left before I can revive my work on the reference. That'll help. Some.
The API reference I was talking about: https://github.com/elastic/elasticsearch/pull/22775
My findings from working with painless a bit:
:goto <character> (not documented, existing issue)au BufRead,BufNewFile *.painless set filetype=groovy (helpful hints?)for (Object it : list) { } (documented)Attached is an example that will traverse each JSON document in order to fix invalid fields names. Can be attached to an ingest pipeline:
@PhaedrusTheGreek Thank you for the feedback here! Appreciate it.
I wouldn't want Emacs to be left out, so:
(add-to-list 'auto-mode-alist '("\\.painless$" . groovy-mode))
(requires groovy-mode to already be installed of course)
in .vimrc , add this for syntax highlighting: au BufRead,BufNewFile *.painless set filetype=groovy
I wouldn't want Emacs to be left out
I would not do this. If we want syntax highlighting, then we should create our own filetype plugins for vim/emacs. Otherwise you will think eg a closure is valid, because of syntax highlighting, but painless does not have closures. Likewise, it would not properly format lambdas, since groovy does not support them.
You can't use groovy shorthand for loop iteration (list.each {}), you must use the Java style syntax: for (Object it : list) { } (documented)
I believe you can do it java style like list.stream.forEach(e -> {code}). Painless doesn't support groovy's funky rules around parameters.
we should create our own filetype plugins for vim/emacs
Sure, I'll add this to my TODO list
@dakrone If/when you find the time to do this, maybe you can just pull from the existing grammar files to know what valid syntax is.
maybe you can just pull from the existing grammar files to know what valid syntax is.
Don't forget the semicolon hacks!
@jdconrad Please find some time to answer StackOverFlow questions, right now it is very hard learning curve.
@Cinerar I'd be happy to. Do you have any particular questions or links to questions that you would like to me to prioritize?
@Cinerar it is more appropriate to open a new issue in http://discuss.elastic.co/ if you have a specific question. I am sure that @jdconrad or any other Engineer will be more than happy to help 馃槂 .
@jdconrad There are not so much of them right now.
http://stackoverflow.com/search?q=%5Belasticsearch%5D+painless
I'm interested in http://stackoverflow.com/questions/42009778/elasticsearch-painless-script-how-to-iterate-in-an-array-of-nested-objects
Thank you.
A few things
params.<your_var> instead of in the base scope.Closing this in favor of (https://github.com/elastic/elasticsearch/issues/23777)
Most helpful comment
Sure, I'll add this to my TODO list