I'm surprised you do not get an error with those examples. The inline key should be taking a string. A json object only works for templates. So I believe, based on how we handle templates, all of your examples will end up creating a string passed to painless that contains curlies (ie a block), and then the only statement inside that block will be a String, which is the last statement, so it will be returned. Looking at the code that should be trying to cast the returned String to a Number and call doubleValue, which should result in a runtime error. Since you don't see that error, something else must be going on (or the error is masked, and 0 is used). Or are you using this within a filter context? That might think there is no score and just return 0.
I think your examples should work. Try something like this:
Thanks for the response. Yes, I only used a string there, not a json object. Since the kibana console cut and paste doesn't work for me under firefox, I had to type it out and for some reason just added a json object there.
I've since found another way to do what I was going for. I gave up on using painless for the time being - it's just too painful without a REPL or interactive object inspector. I'll give it another go once it's out of experimental and the docs are a bit more accessable.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.