[英]Elastic Search: To get all the document id depending on _field in source and update the _field with new data
I wanted to fetch all the document ids present in elastic search repo depending on a field data and update that field with new data. 我想根据字段数据获取弹性搜索库中存在的所有文档ID,并使用新数据更新该字段。
Ex: "_index": "conn2", "_type": "conn2", "_id": "doc1537857086536", "_score": 1, "_source": { "suitename": "TestSuite" 例如:“ _index”:“ conn2”,“ _type”:“ conn2”,“ _id”:“ doc1537857086536”,“ _score”:1,“ _source”:{“ suitename”:“ TestSuite”
I want to replace suitename with "TestSuite2" where suitename="TestSuite" for all the document id which contains "suitename": "TestSuite" 我想将Suitename替换为“ TestSuite2”,其中,对于所有包含“ suitename”的文档ID,suitename =“ TestSuite”:“ TestSuite”
Please help me if any existing API i can use or any approach. 如果我可以使用任何现有的API或任何方法,请帮助我。
Thanks 谢谢
You can use the Update by Query API . 您可以使用Update by Query API 。
Your call would look something like this: 您的通话将如下所示:
[EDIT]: Updated this call to use a script to update the suitename field. [编辑]:更新了此调用,以使用脚本更新套件名称字段。
POST conn2/_update_by_query
{
"script": {
"inline": "ctx._source.suitename = 'TestSuite2'",
"lang": "painless"
},
"query": {
"term": {
"suitename": "TestSuite"
}
}
}
Alternatively, you could also use _reindex . 另外,您也可以使用_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.