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

相关推荐
Cx330❀10 小时前
Linux命名管道(FIFO)通信:从原理到实操,一文搞懂跨进程通信
大数据·linux·运维·服务器·elasticsearch·搜索引擎
Elastic 中国社区官方博客13 小时前
使用 Jina 远程 MCP 服务器的 Agentic 工作流
大数据·运维·人工智能·elasticsearch·搜索引擎·运维开发·jina
历程里程碑18 小时前
二叉树---二叉树的最大深度
大数据·数据结构·算法·elasticsearch·搜索引擎·全文检索·深度优先
大气层煮月亮20 小时前
ERP-Agent 记忆系统优化方案
java·大数据·elasticsearch
coderlin_20 小时前
Langgraph项目 一(mysql,es,qdrant,embedding模块)
mysql·elasticsearch·embedding
倒流时光三十年21 小时前
Elasticsearch SearchRequest 构建备忘录
大数据·elasticsearch
Elastic 中国社区官方博客1 天前
多大才算太大?Elasticsearch 容量规划最佳实践
大数据·运维·数据库·elasticsearch·搜索引擎·全文检索
LDG_AGI1 天前
【搜索引擎】Elasticsearch(四):bool查询(与where类似),多条件搜索利器
大数据·人工智能·深度学习·elasticsearch·机器学习·搜索引擎
Elasticsearch2 天前
使用 Jina 远程 MCP 服务器的 Agentic 工作流
elasticsearch
Elastic 中国社区官方博客2 天前
在 Elastic 中使用 OpenTelemetry 内容包可视化 OpenTelemetry 数据
大数据·开发语言·数据库·elasticsearch·搜索引擎