I'm using painless script in update_by_query to loop through nested array field like this
if( !ctx._source.containsKey("ARRAY_FIELD") ){ctx._source.ARRAY_FIELD=[];}
for( int i = 0; i < ctx._source.ARRAY_FIELD.size(); i ++ )
{
if( ctx._source.ARRAY_FIELD[ i ].KEY == VALUE)
{
ctx._source.ARRAY_FIELD[ i ].FIELD1++;
if( ctx._source.ARRAY_FIELD[ i ].FIELD1 > 0 )
{
ctx._source.ARRAY_FIELD[ i ].FIELD3=(double)ctx._source.ARRAY_FIELD[ i ].FIELD2 / ctx._source.ARRAY_FIELD[ i ].FIELD1;
}
found=1;
break;
}
}
update_by_query query is simple as {query:{ids:[1,2,3,4,5,6,7]}}
Each document's ARRAY_FIELD size is not bigger than 2500 items.
Sometimes I get error "The maximum number of statements that can be executed in a loop has been reached.". What is that limit and how can I increase it? Or maybe there is something wrong with my script?
The limit is 10000. I'll figure out how to change it in a minute, but unless you have a ton of fields or you are doing a lot in each loop it probably means you have some issue with the loop.
Yeah, I could see that getting to the limit. I think it might be worth filing an issue on github about it - specifically mentioning that you are doing _update_by_query instead of search. 2500 is rather a lot of entries in an array to be examining at search time but ought to be fine for update_by_query.
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.