繁体   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