elasticsearch更新给出未知字段错误 [英] elasticsearch update gives unknown field error
问题描述
我正在使用Elasticsearch的Typescript客户端,并且当我尝试更新文档时:
import'@ elastic/elasticsearch'的{RequestParams}const updateParam:RequestParams.Update = {id:"111",索引:"myIndex",正文:{电子邮件:'aaa@aa.ca'},}返回elasticsearchClient.update(updateParam)
我收到一条错误消息:
{错误": {根本原因": [{"type":"x_content_parse_exception","reason":"[1:2] [UpdateRequest]未知字段[id],未找到解析器"}],"type":"x_content_parse_exception","reason":"[1:2] [UpdateRequest]未知字段[id],未找到解析器"},状态":400}
但是根据此处的文档:解决方案
原来,RequestParams.Update应该看起来像这样:
const updateParam:RequestParams.Update = {id:"111",索引:"myIndex",正文:{doc:{email:'aaa@aa.ca'}},}
因此,实际数据将需要包装在"doc"字段中.我将对github上的lib进行PR.
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: 'aaa@aa.ca'},
}
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?
Turned out, the RequestParams.Update should looke like this:
const updateParam: RequestParams.Update = {
id: '111',
index: 'myIndex',
body: {doc:{email: 'aaa@aa.ca'}},
}
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.
这篇关于elasticsearch更新给出未知字段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!