I don't know why, but changing counter type from int to int array solved the issue:
"script_fields" : {
"position": {
"script": {
"source":"params.counter[0]++",
"lang":"painless",
"params":{
"counter": [0]
}
}
}
}