Here my goal is to find an object that matches my condition where start is >= desired AND end <= desired (There is always ONLY one object that will suffice this condition, that's guaranteed in my data storage), once I find that object then I would like to return (it.end - delta) * 2 for score calculation
My above script "doc['mygroup'].values.any{ if(it -> it.end >= desired && it.start <= desired) { return (it.end - delta) * 2} };" is not working and it keeps throwing error. I am using ES 2.3 and groovy for scripting language.
It is weird that sometimes I get different error message saying "reason": "missing_method_exception: No signature of method: java.util.HashMap.call() is applicable for argument types: (e59f5ff9a4ea5a82513a5a8e06fcc8269b487334$_run_closure1$_closure2) values: [e59f5ff9a4ea5a82513a5a8e06fcc8269b487334$_run_closure1$_closure2@6be9b69c]\nPossible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), each(groovy.lang.Closure), max(groovy.lang.Closure)"
So _source and doc should both be available, though I think to get the values for doc you'd need doc['mygroup.start'] and doc['mygroup.end']. The reason is that doc processes things column wise whereas _source uses the source document. I expect doc to be much faster if processing a lot of data.
scripts of type [inline], operation [search] and lang [groovy] are disabled
That makes me suspect at least one of your Elasticsearch nodes doesn't have inline scripts enabled. Those errors should appear in the logs - maybe you can look and find if it is just one node?
Since I need to loop through mygroup object first to find the object that matches my condition, so "script": "doc['mygroup.start'].values.any{.......... will not work, right?
Regardin So _source and doc should both be available doc it doesn't work, it only works with _source
It should work with doc, just differently. More like [doc['mygroup.start'], doc['mygroup.end']].transpose().any { [start, end] -> end >= desired && start <= desired) return (start - delta) * 2
There was a minor typo in your snippet [doc['mygroup.start'], doc['mygroup.end']].transpose().any { [start, end] -> end >= desired && start <= desired) return (start - delta) * 2
Sorry! I'm not really a groovy expert and I just wrote it without trying it against anything. I expect there is a syntax error when I destructure the list around [start, end]. I thought it worked like that but I think it should instead be (start, end). Something like that ought to work for you though.
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.