当前位置:   article > 正文

ES 索引改名_es 索引支持改命吗

es 索引支持改命吗

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

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

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

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

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

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

创建新索引

 

Bash

  1. PUT /new_index_name
  2. {
  3. "settings": {
  4. "number_of_shards": 1,
  5. "number_of_replicas": 0
  6. }
  7. }

复制数据

 

Bash

  1. POST _reindex
  2. {
  3. "source": {
  4. "index": "old_index_name"
  5. },
  6. "dest": {
  7. "index": "new_index_name"
  8. }
  9. }

删除旧索引

 

Bash

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. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/803508
推荐阅读
相关标签
  

闽ICP备14008679号