【问题标题】:elasticsearch update gives unknown field errorelasticsearch更新给出未知字段错误
【发布时间】:2019-08-19 21:54:37
【问题描述】:

我正在使用 Elasticsearch 的 Typescript 客户端,当我尝试更新文档时:

import { RequestParams } from '@elastic/elasticsearch'      
const updateParam: RequestParams.Update = {
      id: '111',
      index: 'myIndex',
      body: {email: 'aaa@aa.ca'},
}
return elasticsearchClient.update(updateParam)

我收到一条错误消息:

{
    "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
}

但是根据这里的文档:https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_updateid是输入中的一个字段

我的请求参数有什么问题?

【问题讨论】:

  • 您也可以发布您的索引映射吗?

标签: typescript elasticsearch


【解决方案1】:

结果,RequestParams.Update 应该如下所示:

const updateParam: RequestParams.Update = {
      id: '111',
      index: 'myIndex',
      body: {doc:{email: 'aaa@aa.ca'}},
}

因此,实际数据需要包装在“doc”字段中。我将在 github 上对 lib 进行 PR...人们无法仅通过文档来弄清楚。

【讨论】:

  • 节省了一天。可能应该在 RequestParams.Update 接口的主体中指定 doc 字段吗?所以我们可以弄清楚。还是谢谢。
  • 不知道这之后Elasticsearch有没有更新文档,不过可以看个例子elastic.co/guide/en/elasticsearch/client/javascript-api/7.x/…await client.update({ index: 'game-of-thrones', id: '1', body: { doc: { isAlive: false } } })
【解决方案2】:

以“doc”键发送正文以解决此问题。我正在使用打字稿和 Elasticsearch 7.8。之前是 6.7 版本,没有发现任何问题,但在迁移到新版本后开始获得它。

【讨论】:

    【解决方案3】:

    这个'id'不是你文档内容中的一个字段。它就像'index'和'type'。当你更新一个文档时你不能改变索引的名称和类型,所以你不能改变一个文档的id。是文档的标识。但是如果你有一个名为'id'的字段,你可以这样更新。

    【讨论】:

    • 如果我不提供id,ES如何知道要更新哪个文档?
    • 您作为参数传递给更新调用的顶级对象上的 id 参数是您可以在 Elasticsearch 响应中看到的 _id。您的文档中可能有或没有 id 属性。 @jamesdeath123。第一个问题的真正问题是要更新的文档对象没有包装在 doc 属性内的 body 参数中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多