I am using the Elasticsearch's Typescript client, and when I try to update a document:
import { RequestParams } from '@elastic/elasticsearch'
const updateParam: RequestParams.Update = {
id: '111',
index: 'myIndex',
body: {email: '[email protected]'},
}
return elasticsearchClient.update(updateParam)
I am getting an error saying:
{
"error": {
"root_cause": [
{
"type": "x_content_parse_exception",
"reason": "[1:2] [UpdateRequest] unknown field [id], parser not found"
}
],
"type": "x_content_parse_exception",
"reason": "[1:2] [UpdateRequest] unknown field [id], parser not found"
},
"status": 400
}
But according to the document here: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_update, id
is a field in the input
What's wrong with my request param?
Updates a document using the specified script. If the Elasticsearch security features are enabled, you must have the index or write index privilege for the target index or index alias. Enables you to script document updates.
If the Elasticsearch security features are enabled, you must have the index or write index privilege for the target index or index alias. Enables you to script document updates. The script can update, delete, or skip modifying the document.
Elasticsearch version : 6.2.3 Show activity on this post. File scripts have been removed in ES 6.0, you should now use stored scripts instead. You can easily migrate your Groovy script to Painless. Thanks for contributing an answer to Stack Overflow!
Thanks very much for your interest in Elasticsearch. Sorry, something went wrong. Thanks for taking this up. Yes, as you have mentioned, it works when we use it as a URL parameter. Sorry, something went wrong. Any progress on the topic ?!
Turned out, the RequestParams.Update should looke like this:
const updateParam: RequestParams.Update = {
id: '111',
index: 'myIndex',
body: {doc:{email: '[email protected]'}},
}
So the actual data will need to be wrapped in "doc" field. I will make a PR to the lib on github... there is no way people can just figure it out by just the documentation.
Send the body in "doc" key to resolve this problem. I am using typescript along with Elasticsearch 7.8. Earlier it was 6.7 version where found no issues but started getting it after migration to newer version.
This 'id' is not a field in your document content.It just like 'index' and 'type'.You can't change index's name and type when you update one document,so you can't change one document's id.It is the identification of a document.But if you have a field named 'id',you can update like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With