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

相关推荐
Java展博6 小时前
[工程化基本功] 合并两条分支时,merge 和 rebase 到底改了谁的历史
大数据·elasticsearch·搜索引擎
Elasticsearch1 天前
借助 AWS Quick 和 Elastic Agent Builder 的 MCP 服务器,用自然语言查询百万笔交易
elasticsearch
Elasticsearch2 天前
你的第 95 百分位数掩盖了 95% 的请求,而 ES|QL 直方图能展示这些请求的分布
elasticsearch
崖边看雾2 天前
Git 手册:三区、分支、撤销、冲突与团队协作
大数据·git·elasticsearch
飞奔的瓜牛3 天前
Elasticsearch 日常巡检清单与实战避坑指南
大数据·elasticsearch·搜索引擎
Elasticsearch3 天前
数据摄取路径原本只在某个人的脑子里,Elastic Streams Map 能把它画出来
elasticsearch
岳涛3 天前
考古|_parent 在 ES 2.0 被重写,老索引不重建就用不上新实现
elasticsearch
Elasticsearch3 天前
两行,一个文档:在 Logstash 中配对 Elasticsearch 批量操作
elasticsearch
顧棟4 天前
Elasticsearch LifecycleComponent 组件生命周期设计分析
大数据·elasticsearch
Elasticsearch4 天前
在 Kibana Agent Builder 中创建 Agent,并为它添加自定义 Skill
elasticsearch