ES 索引改名

在Elasticsearch中,直接重命名索引并不是一个直接支持的操作。但是,可以通过以下步骤间接实现索引的重命名:

  1. 创建新索引:首先,你需要创建一个新的索引,这个索引将是你原索引的新名字。

  2. 复制数据:使用Reindex API将数据从旧索引复制到新索引。

  3. 删除旧索引:确认新索引创建成功并验证数据完整后,可以安全地删除旧索引。

  4. 更新应用配置:最后,确保你的应用程序或其他依赖于这个索引的服务指向新的索引名称。

以下是如何使用Curl命令执行上述步骤的示例:

创建新索引

 

Bash

PUT /new_index_name
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

复制数据

 

Bash

POST _reindex
{
  "source": {
    "index": "old_index_name"
  },
  "dest": {
    "index": "new_index_name"
  }
}

删除旧索引

 

Bash

1DELETE /old_index_name

请注意,这些操作应该在低峰时段执行,以减少对生产环境的影响。同时,在删除旧索引之前,一定要确保新索引中的数据完整无误。

此外,Elasticsearch 7.10及以上版本提供了_migrate API,可以更方便地进行索引的重命名和迁移,但具体的使用方法和注意事项需要参考官方文档。不过,截至我最后一次更新知识(2023年初),直接的索引重命名API并未在文档中提及,因此以上方法仍然适用。

-----------------------------------------------------------------

备份流程

PUT /content_erp_nlp_help_back
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

POST _reindex
{
  "source": {
    "index": "content_erp_nlp_help"
  },
  "dest": {
    "index": "content_erp_nlp_help_back"
  }
}

DELETE /content_erp_nlp_help



DELETE /content_erp_nlp_help

PUT /content_erp_nlp_help

PUT _template/content_erp_nlp_help
{
  "index_patterns": [
    "content_vector*"
  ],
  "settings": {
    "analysis": {
      "analyzer": {
        "my_ik_analyzer": {
          "type": "ik_smart"
        }
      }
    },
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "long"
      },
      "content": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "content_vector": {
        "type": "dense_vector",
        "similarity": "cosine",
        "index": true,
        "dims": 768,
        "element_type": "float",
        "index_options": {
          "type": "hnsw",
          "m": 16,
          "ef_construction": 128
        }
      },
      "content_answer": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "title": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "param": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "type": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "questionId": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "createTime": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "updateTime": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "hitCount": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "answerPattern": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "nearQuestionVOList": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "questionEnclosureVOList": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "questionRelationVOList": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "rmsRoutingAnswerVos": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      }
    }
  }
}

POST _reindex
{
  "source": {
    "index": "content_erp_nlp_help_test"
  },
  "dest": {
    "index": "content_erp_nlp_help"
  }
}

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值