gpt4 book ai didi

node.js - 如何在响应中获取更新的文档

转载 作者:行者123 更新时间:2023-12-02 22:21:23 26 4
gpt4 key购买 nike

let elasticsearch = require('elasticsearch');

let client = new elasticsearch.Client({
host: "*********************",
});

let temp = await client.update({
index: container,
id: 1,
type: '_doc',
body: {"name": "rks", "visible": true},
doc_as_upsert: true,

})

此查询的响应返回
"result": {
"_index": "container",
"_type": "_doc",
"_id": "1",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}

如何在响应中返回更新的文档。有没有办法/方法来实现这个目标。请帮我

最佳答案

你能做的最好的事情就是设置 "_source": true .这样您就可以取回文档源。

例如

POST test/_update/1
{
"doc":{
"hello": "world",
"hey": "there"
},
"_source": true,
"doc_as_upsert": true
}

示例响应:
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"get" : {
"_seq_no" : 2,
"_primary_term" : 1,
"found" : true,
"_source" : {
"hello" : "world",
"hey" : "there"
}
}
}

关于node.js - 如何在响应中获取更新的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60884141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com