Very new to this Painless Scripting, and I'm finding a lot of Pain with it. It's nothing like any scripting languages I've used in the past. I'm 100% sure that this is a syntax issue but cannot figure it out.
I have a static index with a large amount of documents, and wanting to create a unique identifiable field. I have created a mapping called "doc_id" as an Integer and set all values to 0 to begin with.
I'm trying to form a for-loop to iterate through all items in the index and increase the doc_id by 1, for each document that exists.
POST index-name/_update_by_query?conflicts=proceed&&wait_for_completion=false
{
"script": : {
"source": """
int i = 0;
for (item in ctx._source['doc_id']) {
ctx._source['doc_id']=i;
i++;
}
"""
}.
"query": {
"match_all": {}
}
}
Error: Type: Illegal_argument_exception" Reason: "Cannot iterate over [java.lang.Integer]"
Am I approaching this the right way? How am I meant to define a list to iterate over? I thought this is what the "query" was.