莫张周刘王 发表于 2024-8-15 22:05:00

ES 索引改名

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

[*] 创建新索引:起首,你需要创建一个新的索引,这个索引将是你原索引的新名字。
[*] 复制数据:使用Reindex API将数据从旧索引复制到新索引。
[*] 删除旧索引:确认新索引创建成功并验证数据完整后,可以安全地删除旧索引。
[*] 更新应用配置:最后,确保你的应用步调或其他依赖于这个索引的服务指向新的索引名称。
以下是如何使用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"
}
}

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