更新给定ID的Elasticearch记录时出现错误[]

yb3bgrhw  于 2022-10-06  发布在  ElasticSearch
关注(0)|答案(2)|浏览(134)

我正在尝试更新ES记录中的一个字段,但它出错了。

ES JSON文档

{
  "_index": "Barroz",
  "_type": "_doc",
  "_id": "pGcGz3gBRea5RG",
  "_version": 67,
  "_score": 1,
  "_source": {
    "tid": "f90a48519ceeb9e43f21898363b59",
    "taep": "test.treat",
    "cluster": "Barroz.GuardianofDGamasTreasure",
    "state": "Failure",
    "notes": "Looks good"
  }
}

我正在尝试的是:

elastic_client = Elasticsearch(["http://localhost:9200"])

query_body = {"_source": { "state": "Success" } }

elastic_client.update(index="Barroz", doc_type="_doc", id=pGcGz3gBRea5RG, 
body=query_body)

我收到以下错误:

status_code, error_message, additional_info
elasticsearch.exceptions.RequestError: RequestError(400, 'x_content_parse_exception', 'Unknown key for a VALUE_STRING in [state].')

请告诉我出了什么差错。

ezykj2lf

ezykj2lf1#

update终结点接受以下正文,即只需将_source替换为doc

query_body = {"doc": { "state": "Success" } }
hxzsmxv2

hxzsmxv22#

ElasticSearch 7.17docs中提到了将正文 Package 在doc键中以执行文档的部分更新。

{
    "doc": {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3"
    }
}

相关问题