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 集群的性能产生影响。建议在低峰时段进行这些操作。

相关推荐
Elastic 中国社区官方博客1 小时前
使用 Elasticsearch 管理 agentic 记忆
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
七夜zippoe6 小时前
Elasticsearch核心概念与Java客户端实战 构建高性能搜索服务
java·大数据·elasticsearch·集群·索引·分片
忍冬行者20 小时前
Elasticsearch 超大日志流量集群搭建(网关 + 独立 Master + 独立 Data 纯生产架构,角色完全分离,百万级日志吞吐)
大数据·elasticsearch·云原生·架构·云计算
·云扬·1 天前
使用Prometheus+Grafana实现Elasticsearch监控的完整实践
elasticsearch·grafana·prometheus
阿杰 AJie1 天前
Git 分支与多人开发使用指南(Gitee + 本地 Git)
git·elasticsearch·gitee
海鸥811 天前
ArgoCD App of Apps 模式详解
java·elasticsearch·argocd
Dxy12393102161 天前
深度解析 Elasticsearch 8.13.4 范围查询 DSL
大数据·elasticsearch
Zilliz Planet1 天前
官宣 | Milvus 2.6云上GA:三层存储降本85% 、速度快ES 4-7 倍,多数据类型支持
大数据·elasticsearch·搜索引擎·全文检索·milvus
峥嵘life1 天前
Android16 系统每月Google安全补丁导入说明
大数据·elasticsearch·搜索引擎
Dxy12393102161 天前
Elasticsearch 8.13.4 地理范围查询实战指南
大数据·elasticsearch·jenkins