簡體   English   中英

如何在響應中獲取更新的文檔

[英]How can I the get updated document in the response

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM