弹性搜索合并两个索引

问题描述

Reindex 不能用于合并两个索引。 Reindex 会在目标索引中进行完整更新。

考虑以下索引 my-new-index-000001

GET my-new-index-000001/_doc/6
{
  "_index" : "my-new-index-000001","_type" : "_doc","_id" : "6","_version" : 26,"_seq_no" : 34,"_primary_term" : 16,"found" : true,"_source" : {
    "field2" : "value2","field1" : "value1"
  }
}

上面的索引有两个字段field1和field2。

以下代码段用于将源字段 (new_field) 重新索引到目标:

# reindex that field
POST _reindex
{
  "source": {
    "index": ["my-index-000001"],"query": {
      "terms": {
        "_id": [6]
      }
    },"_source":["new_field"]
  },"dest": {
    "index": "my-new-index-000001"
  }
}

重新索引后,这是更新后的my-new-index-000001索引

GET my-new-index-000001/_doc/6
{
  "_index" : "my-new-index-000001","_version" : 27,"_seq_no" : 35,"_source" : {
    "new_field" : false
  }
}

有没有办法在弹性搜索中根据公共字段从源到目标进行部分更新? 有没有办法使用 python 脚本来实现这一点。 请分享一个工作片段或参考。

解决方法

您可以使用 Update By Query API

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html