es的_reindex如何排除一个或者多个字段?

文章介绍了如何使用Elasticsearch的_reindexAPI来移除单个或多个字段,并且展示了如何仅覆盖特定字段而不改变其他字段的数据。通过提供源索引和目标索引,结合脚本操作,可以实现对文档字段的精确控制。
一、移除一个字段
POST _reindex
{
  "source": {
    "index": "source_index"
  },
  "dest": {
    "index": "destination_index"
  },
  "script": {
    "source": "ctx._source.remove('field_to_exclude')"
  }
}

二、移除多个字段
POST _reindex
{
  "source": {
    "index": "source_index"
  },
  "dest": {
    "index": "destination_index"
  },
  "script": {
    "source": """
      for (def field : params.fieldsToRemove) {
        ctx._source.remove(field);
      }
    """,
    "params": {
      "fieldsToRemove": ["field1", "field2", "field3"]
    }
  }
}

elasticsearch的_reindex根据_id只覆盖一个字段而其他字段不动

POST _reindex
{
  "source": {
    "index": "index_a",
    "query": {
      "match_all": {}
    }
  },
  "dest": {
    "index": "index_b"
  },
  "script": {
    "source": "ctx._source.AA = ctx._source.AA"
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值