Reputation: 11391
After reading this article here i can't manage to translate the following SQL to elastic dsl:
UPDATE myIndex
set field1 = staticValue1, field2 = staticValue2
Where {
"query": {
"bool": {
"must_not": {
"exists": {
"field": "cnpj_estabelecimento"
}}}}}
How can I do this?
Upvotes: 0
Views: 270
Reputation: 1428
When working with the Update By Query API, you have two parts:
Query. What elements will be updated.
Script. What changes will be done.
For the script part, you will have to play a little with Painless. Don't trust the name: Learning Painless is Painful (at the beginning).
Now, for your particular case, the thing you want to do, should look like this:
POST /myIndex
"query" : {
"bool" : {
"must_not" : {
"exists" : {
{
"field": "cnpj_estabelecimento"
}
}
}
}
},
"script" : {
"inline" : "ctx._source.field1= 'staticValue1'; ctx._source.field2= staticValue2;",
"lang" : "painless"
}
}
Note than when you call the Update By Query API you do it via POST, not UPDATE.
Hope this is helpful! :D
Upvotes: 1