Elasticsearch 不允许直接修改现有索引的映射来添加新字段

由于 Elasticsearch 不允许直接修改现有索引的映射来添加新字段,您需要采取以下步骤来添加新字段:

  1. **创建新索引**:

创建一个新的索引,包含原始字段和您想要添加的新字段 `content`。

```json

PUT /new_article

{

"mappings": {

"_doc": {

"properties": {

"title": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_max_word"

},

"desc": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_max_word"

},

"content": { // 新增字段

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_max_word"

}

}

}

}

}

```

  1. **迁移数据**:

使用 `_reindex` API 将数据从旧索引 `article` 迁移到新索引 `new_article`。

```json

POST /_reindex

{

"source": {

"index": "article"

},

"dest": {

"index": "new_article"

}

}

```

  1. **更新别名** (如果使用):

如果您使用别名,需要更新别名指向新的索引。

```json

POST /_aliases

{

"actions": [

{

"remove": {

"index": "article",

"alias": "article_alias" // 假设您的别名是 article_alias

}

},

{

"add": {

"index": "new_article",

"alias": "article_alias"

}

}

]

}

```

  1. **删除旧索引** (可选):

在确认新索引工作正常并且别名已经更新之后,您可以删除旧的索引以释放资源。

```json

DELETE /article

```

  1. **更新应用程序配置**:

更新您的应用程序配置,确保它指向新的索引或别名。

请注意,这个过程涉及到数据迁移,因此在执行这些步骤之前,请确保您已经备份了数据,以防止数据丢失。此外,根据您的数据量大小,迁移数据可能需要一些时间,并且可能会对 Elasticsearch 集群的性能产生影响。建议在低峰时段进行这些操作。

相关推荐
阿里云大数据AI技术3 小时前
Agentic Search 2.0:从单轮对话迈向企业级 AI 搜索自动驾驶Agent
人工智能·elasticsearch·agent
Elasticsearch6 小时前
你的 AI agent 需要一个不在场证明:Elastic 中 Agent Builder 的可观测性和审计追踪
elasticsearch
Elasticsearch10 小时前
仪表板活动日志:了解哪些 Kibana 仪表板会被使用
elasticsearch
Elasticsearch1 天前
从 22.61GB 到 15.63GB:Elasticsearch 9.5 如何用「混合存储」重新定义日志数据库
elasticsearch
Elasticsearch1 天前
用于自托管 LLM 调优的 vLLM Prometheus 指标:TTFT、KV Cache 和 GPU 利用率
elasticsearch
Sayai2 天前
Elasticsearch 快照备份到 NAS(NFS)实战:SLM 自动化 + 365 天保留策略
elasticsearch·自动化·jenkins
JavaPub-rodert2 天前
写软著 - Copyright Forge Skill 完整闭环改造方案
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客2 天前
从建议到修复的 4 个阶段:使用 Elastic Workflows 实现人在回路中的自动化
运维·数据库·人工智能·后端·elasticsearch·ai·自动化
Elasticsearch3 天前
使用 OpenTelemetry 进行 Android 应用监控:从点击到后端的分布式追踪
elasticsearch
Elasticsearch3 天前
安心睡过凌晨 3 点的告警:在 Red Hat OpenShift 上使用 Elastic 实现自动化故障事件响应
elasticsearch