Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch update gives unknown field error

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?

like image 587
jamesdeath123 Avatar asked Aug 19 '19 21:08

jamesdeath123


People also ask

How do I update a document in Elasticsearch?

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.

What are the security features of Elasticsearch?

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.

What is the latest version of Elasticsearch for painless?

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!

Does Elasticsearch work with URL parameter?

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 ?!


Video Answer


3 Answers

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.

like image 143
jamesdeath123 Avatar answered Oct 24 '22 03:10

jamesdeath123


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.

like image 6
Shivam Pandey Avatar answered Oct 24 '22 05:10

Shivam Pandey


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.

like image 1
user9940960 Avatar answered Oct 24 '22 04:10

user9940960