简体   繁体   English

弹性搜索:根据源中的_field获取所有文档ID,并使用新数据更新_field

[英]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”

  • I tried using Update API where as it is required to mention document id. 我尝试使用Update API,因为它需要提及文档ID。

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.

相关问题 Java,Lucene:通过保存的Id获取文档,然后更新其中一个字段 - Java, Lucene : Get document by saved Id and then update one of it's field Firestore按文档ID或文档字段搜索和排序,哪个更好? - Firestore search and order by document id or by document field, which is a better way? 通过_id更新一个文档(无效的BSON字段名称_id) - Update one document by _id (Invalid BSON field name _id) Spring Data弹性搜索嵌套字段和NativeSearchQueryBuilder.withFields - Spring Data Elastic Search Nested Field and NativeSearchQueryBuilder.withFields Spring Data Elastic Search 4.0.3 - 日期字段列表 - Spring Data Elastic Search 4.0.3 - List Of Dates Field 搜索排序通过它查询在弹性搜索中对单个文档的_source内的数据进行分页 - Search sort paginate the data inside _source of a single document in elastic search through it query 弹性搜索中使用_id作为文档标识符 - Use of _id for document identifier in elastic search 弹性搜索 java 客户端 mapper_parsing_exception 未能解析文档中 [long] 类型的字段 [timeStamp]? - elastic search java client mapper_parsing_exception failed to parse field [timeStamp] of type [long] in document? 查询包含和不包含字符的弹性文档字段 - Query Elastic document field with and without characters Java RestHighLevelClient - 弹性搜索 - 如何在 id 字段值中添加特殊字符“/” - Java RestHighLevelClient - Elastic Search - How to add special character '/' in id field value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM