Hello,
I have documents having one field : numberReqs
when I execute :
client.update({
index: 'index',
type: 'type',
id: 'id',
body: {
script: "def docSrc = ctx._source; docSrc.numberReqs+=nubmerReqsToAdd;",
params: {
nubmerReqsToAdd: 1
},
upsert: {
numberReqs: 0
}
}
}, (err) => { console.log(err) })
This code throws document_missing_exception even if I mentioned the upsert.
Hi! It looks like that your body is not well formed.
Can you try in this way?
client.update({
index: 'index',
type: 'type',
id: 'id',
body: {
script: {
source: 'def docSrc = ctx._source; docSrc.numberReqs+=nubmerReqsToAdd;',
lang: 'painless',
params: {
nubmerReqsToAdd: 1
}
},
upsert: {
numberReqs: 0
}
}
}, (err) => { console.log(err) })
I suggest you to take a look to our awesome documentation :)
Thank you for your reply.
It worked perfectly ! but to read the param, we use
params.nubmerReqsToAdd
The js documentation must be updated than,
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-update
As you can see, upsert & params & script are always in the same level, so we have to mention, when we are going to use upsert & params, we have to use the given format.
Thank you again.
We understand that this might be important for you, but this issue has been automatically marked as stale because it has not had recent activity either from our end or yours.
It will be closed if no further activity occurs, please write a comment if you would like to keep this going.
Note: in the past months we have built a new client, that has just landed in master. If you want to open an issue or a pr for the legacy client, you should do that in https://github.com/elastic/elasticsearch-js-legacy