Hello!
I'm trying to create a watcher with a condition that uses a Map and keep getting a syntax error.
For example the following code does not compile:
"condition": {
"script": {
"source": """
Map test = [:];
for (entry in test.entrySet())
{
}
return false;
""",
"lang": "painless"
}
I tried various combination of "for (t in test)" or "for (def t : test)", but the only thing that works is:
Map test = [:];
for (def i=0; i<test.size(); i++)
{
}
But I'm confused how I am supposed to access the keys from there.
What is the proper way to access a key/value object like Map in this context?
thank you so much for your answer. The issue was that my for loop was empty (as I was very ironically just testing the syntax)! As soon as I added a line between the {}, it worked.
That sounds like a bug in painless interpreter; I would assume that a language should allow empty loop.
Anyway, thanks a lot for your reply, I was stuck on that for a while!
Thanks for circling back. It's an intentional feature to enhance usability and performance. In many painless contexts, the script will run once per document and there may be millions of documents.
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.