簡體   English   中英

彈性搜索:根據源中的_field獲取所有文檔ID,並使用新數據更新_field

[英]Elastic Search: To get all the document id depending on _field in source and update the _field with new data

我想根據字段數據獲取彈性搜索庫中存在的所有文檔ID,並使用新數據更新該字段。

例如:“ _index”:“ conn2”,“ _type”:“ conn2”,“ _id”:“ doc1537857086536”,“ _score”:1,“ _source”:{“ suitename”:“ TestSuite”

我想將Suitename替換為“ TestSuite2”,其中,對於所有包含“ suitename”的文檔ID,suitename =“ TestSuite”:“ TestSuite”

  • 我嘗試使用Update API,因為它需要提及文檔ID。

如果我可以使用任何現有的API或任何方法,請幫助我。

謝謝

您可以使用Update by Query API

您的通話將如下所示:

[編輯]:更新了此調用,以使用腳本更新套件名稱字段。

POST conn2/_update_by_query
{
  "script": {
    "inline": "ctx._source.suitename = 'TestSuite2'",
    "lang": "painless"
  },
  "query": {
    "term": {
      "suitename": "TestSuite"
    }
  }
}

另外,您也可以使用_reindex

POST _reindex
{
  "source": {
    "index": "conn2"
  },
  "dest": {
    "index": "new_index"
  },
  "script": {
    "source": "if (ctx._source.suitename == 'TestSuite') {ctx._source.suitename = 'TestSuite2'}",
    "lang": "painless"
  }
}

暫無
暫無

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

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