Hi all,
I have a question regarding removing an existing field if contained a specific string.
What I did:
I update documents by this Post:
POST /myindex/_update_by_query
{
"script": {
"source": "ctx._source.tags= 'Test'",
"lang": "painless"
},
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"Custo" : "80010"}},
{ "term" : {"AreaNr" : "962497"}}
]
}
}
}
}
}
And if whatsoever happened I need to remove this entries afterwards by trying this:
POST /myindex/_update_by_query?conflicts=proceed
{
"script" : "ctx._source.tags.remove = 'Test'",
"query" : {
"exists": { "field": "tags" }
}
}
Or this:
POST /myindex/_update_by_query?conflicts=proceed
{
"script" : {
"source": "if (ctx._source.tags.contains('Test')) { ctx._source.tags.remove(ctx._source.tags.indexOf('Test')) }",
"lang": "painless"
}
}
But neither of the remove Posts works as expected.
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.tags.remove = 'Test'",
" ^---- HERE"
],
"script": "ctx._source.tags.remove = 'Test'",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.tags.remove = 'Test'",
" ^---- HERE"
],
"script": "ctx._source.tags.remove = 'Test'",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "dynamic setter [java.lang.String, remove] not found"
}
},
"status": 400
}
And what about:
"script":{"inline":"ctx._source.tags.removeAll
How does this works ?
Hope you can help
Thanks and regards