Painless script loop maximum number of statements limit

Hi there

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?

Thanks

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.

It looks like the way to change it is:

POST test/test/1/_update
{
  "script": {
    "inline": "int j = 0; for (int i = 0; i++; i < 5) {j++} return j",
    "options": {
      "max_loop_counter": 10   <---- this
    }
  }
}

But that doesn't work because it isn't allowed. So I'm fairly sure changing it isn't supported. I thought it was though....

Thanks for reply. I've edited my question with more details about the loop and query

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.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.