Hi,
im using Version 6.2. There is no error message, however, when if statement (if(doc['formular.pages'][i] > doc['formular.pages'][i + 1])) is true no new scripted field is added, only when the statement is false, a new field with 0 is added.
I also tried to rewrite this script:
def pages = new ArrayList();
def j;
if(doc['formular.pages'].length > 1) {
for(int i = 0; i < doc['formular.pages'].length - 1;) {
j = i;
++i;
if(doc['formular.pages'][i] < doc['formular.pages'][j]){
pages.add(doc['formular.pages'][j]);
}
}
}else{
pages.add(0);
}
return pages;
@aleksa I believe that you're running into an issue with the way that Elasticsearch indexes and orders arrays. If you query your index for only the formular.pages you'll always see the pages always returned in order.
If you'd like to get the formular.pages in the original order when they were indexed, you can use the params._source.formular.pages to access this and use it throughout your script:
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.