We are using update_by_query
to add/modify some of the fields in our documents. The update is working fine. However, it is adding an additional field "ctx" in each of the document:
Here is the query I am using :
POST test/_update_by_query
{
"size": 1000,
"query": {
"match_all": {}
},
"script": {
"lang": "painless",
"source":"""for (entry in params.entrySet()){ctx._source[entry.getKey()] = entry.getValue()}""",
"params": {
"gender": "female",
"age": 12,
"first_name": "John"
}
}
}
The document before running the query:
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"first_name" : "Jane",
"last_name" : "Doe"
}
}
]
}
}
After running update_by_query
:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"gender" : "female",
"ctx" : {
"_routing" : null,
"_parent" : null,
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : -1
},
"last_name" : "Doe",
"first_name" : "John",
"age" : 12
}
}
]
}
}
I am not able to understand this behavior. Is this the way it works or am I doing something wrong in the script?