ES 索引改名

打印 上一主题 下一主题

主题 912|帖子 912|积分 2736

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

  • 创建新索引:起首,你需要创建一个新的索引,这个索引将是你原索引的新名字。
  • 复制数据:使用Reindex API将数据从旧索引复制到新索引。
  • 删除旧索引:确认新索引创建成功并验证数据完整后,可以安全地删除旧索引。
  • 更新应用配置:最后,确保你的应用步调或其他依赖于这个索引的服务指向新的索引名称。
以下是如何使用Curl命令执行上述步调的示例:
创建新索引
  1. [/code] Bash
  2. [code]PUT /new_index_name
  3. {
  4.   "settings": {
  5.     "number_of_shards": 1,
  6.     "number_of_replicas": 0
  7.   }
  8. }
复制代码
复制数据
  1. [/code] Bash
  2. [code]POST _reindex
  3. {
  4.   "source": {
  5.     "index": "old_index_name"
  6.   },
  7.   "dest": {
  8.     "index": "new_index_name"
  9.   }
  10. }
复制代码
删除旧索引
  1. [/code] Bash
  2. [code]1DELETE /old_index_name
复制代码
请注意,这些操纵应该在低峰时段执行,以减少对生产情况的影响。同时,在删除旧索引之前,肯定要确保新索引中的数据完整无误。
此外,Elasticsearch 7.10及以上版本提供了_migrate API,可以更方便地进行索引的重命名和迁移,但详细的使用方法和注意事项需要参考官方文档。不过,截至我最后一次更新知识(2023年初),直接的索引重命名API并未在文档中提及,因此以上方法仍然适用。

-----------------------------------------------------------------
备份流程

  1. PUT /content_erp_nlp_help_back
  2. {
  3.   "settings": {
  4.     "number_of_shards": 1,
  5.     "number_of_replicas": 0
  6.   }
  7. }
  8. POST _reindex
  9. {
  10.   "source": {
  11.     "index": "content_erp_nlp_help"
  12.   },
  13.   "dest": {
  14.     "index": "content_erp_nlp_help_back"
  15.   }
  16. }
  17. DELETE /content_erp_nlp_help
  18. DELETE /content_erp_nlp_help
  19. PUT /content_erp_nlp_help
  20. PUT _template/content_erp_nlp_help
  21. {
  22.   "index_patterns": [
  23.     "content_vector*"
  24.   ],
  25.   "settings": {
  26.     "analysis": {
  27.       "analyzer": {
  28.         "my_ik_analyzer": {
  29.           "type": "ik_smart"
  30.         }
  31.       }
  32.     },
  33.     "number_of_shards": 1
  34.   },
  35.   "mappings": {
  36.     "properties": {
  37.       "id": {
  38.         "type": "long"
  39.       },
  40.       "content": {
  41.         "type": "text",
  42.         "analyzer": "ik_max_word",
  43.         "search_analyzer": "ik_smart"
  44.       },
  45.       "content_vector": {
  46.         "type": "dense_vector",
  47.         "similarity": "cosine",
  48.         "index": true,
  49.         "dims": 768,
  50.         "element_type": "float",
  51.         "index_options": {
  52.           "type": "hnsw",
  53.           "m": 16,
  54.           "ef_construction": 128
  55.         }
  56.       },
  57.       "content_answer": {
  58.         "type": "text",
  59.         "analyzer": "ik_max_word",
  60.         "search_analyzer": "ik_smart"
  61.       },
  62.       "title": {
  63.         "type": "text",
  64.         "analyzer": "ik_max_word",
  65.         "search_analyzer": "ik_smart"
  66.       },
  67.       "param": {
  68.         "type": "text",
  69.         "analyzer": "ik_max_word",
  70.         "search_analyzer": "ik_smart"
  71.       },
  72.       "type": {
  73.         "type": "text",
  74.         "analyzer": "ik_max_word",
  75.         "search_analyzer": "ik_smart"
  76.       },
  77.       "questionId": {
  78.         "type": "text",
  79.         "analyzer": "ik_max_word",
  80.         "search_analyzer": "ik_smart"
  81.       },
  82.       "createTime": {
  83.         "type": "text",
  84.         "analyzer": "ik_max_word",
  85.         "search_analyzer": "ik_smart"
  86.       },
  87.       "updateTime": {
  88.         "type": "text",
  89.         "analyzer": "ik_max_word",
  90.         "search_analyzer": "ik_smart"
  91.       },
  92.       "hitCount": {
  93.         "type": "text",
  94.         "analyzer": "ik_max_word",
  95.         "search_analyzer": "ik_smart"
  96.       },
  97.       "answerPattern": {
  98.         "type": "text",
  99.         "analyzer": "ik_max_word",
  100.         "search_analyzer": "ik_smart"
  101.       },
  102.       "nearQuestionVOList": {
  103.         "type": "text",
  104.         "analyzer": "ik_max_word",
  105.         "search_analyzer": "ik_smart"
  106.       },
  107.       "questionEnclosureVOList": {
  108.         "type": "text",
  109.         "analyzer": "ik_max_word",
  110.         "search_analyzer": "ik_smart"
  111.       },
  112.       "questionRelationVOList": {
  113.         "type": "text",
  114.         "analyzer": "ik_max_word",
  115.         "search_analyzer": "ik_smart"
  116.       },
  117.       "rmsRoutingAnswerVos": {
  118.         "type": "text",
  119.         "analyzer": "ik_max_word",
  120.         "search_analyzer": "ik_smart"
  121.       }
  122.     }
  123.   }
  124. }
  125. POST _reindex
  126. {
  127.   "source": {
  128.     "index": "content_erp_nlp_help_test"
  129.   },
  130.   "dest": {
  131.     "index": "content_erp_nlp_help"
  132.   }
  133. }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

莫张周刘王

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表