【问题标题】:How can I the get updated document in the response如何在响应中获取更新的文档
【发布时间】:2020-07-08 01:58:47
【问题描述】:
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
}

如何在响应中返回更新后的文档。有什么方法/方法可以实现这个目标。请帮帮我

【问题讨论】:

  • 您需要在更新后执行 GET 以获得最新版本的文档
  • 感谢您的回复。但我没有兴趣使用另一个 API 来获得结果。
  • 这就是它的工作原理:-)

标签: node.js elasticsearch amazon-elastic-beanstalk


【解决方案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"
    }
  }
}

【讨论】:

  • 我们能不能得到之前的状态
猜你喜欢
  • 2021-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-08
  • 1970-01-01
相关资源
最近更新 更多