ElasticSearch 学习笔记:Reindex

本文目录

1 创建新的索引(Index)

2 导入数据(Reindex)

3 批量更新(Update by Query)

4 新建/删除别名(Alias)

5 相关文章


1 创建新的索引(Index)

注意:若需要向已存在的索引迁移数据,则不需要创建新的索引。

PUT /<indexName>
{
  "settings": {
    "index": {
      "number_of_shards": 5,
      "number_of_replicas": 1
    }
  }
}


2 导入数据(Reindex)

POST /_reindex
{
  "source": {
    "index": "<sourceIndexName>",
    "type": "<sourceTypeName>",
    "query": {
      ...
    },
    "sort": {
      "<fieldName>": "asc/desc"
    },
    "size": <sizeNum>,
    "_source": [
      "<fieldName>",
      "<fieldName>",
      ...
    ]
  },
  "dest": {
    "index": "<destIndexName>",
    "version_type": "internal(default)/external",
    "op_type": "create"
  }
}

说明:

(1)version_type:

internal 表示迁移全部数据 且 完全覆盖冲突文档(即使目标索引文档版本新于源索引文档)。

external 表示迁移全部数据 且 更新旧版本冲突文档。

(2)op_type:

create 表示仅创建目标索引不存在的文档。


3 批量更新(Update by Query)

POST /<indexName>/<typeName>/_update_by_query
{
  "query": {
    "match_all": {}
  },
  "script": {
    "inline/source": "ctx._source.<fieldName> = ctx._source.<fieldName> + ''"
  }
}

说明:

inline:ES 5.6版本之前;

source:ES 5.6版本及以后

4 新建/删除别名(Alias)

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "<indexName>",
        "alias": "<alias>"
      }
    }
  ]
}

{
  "actions": [
    {
      "remove": {
        "index": "<indexName>",
        "alias": "<alias>"
      }
    }
  ]
}

5 相关文章

《ElasticSearch 学习笔记:常用内容》

《ElasticSearch 学习笔记:Mapping》

《ElasticSearch 学习笔记:Multi Search》

《ElasticSearch 学习笔记:聚合(Aggregation) - Top Hits》

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值