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

相关推荐
Elasticsearch1 小时前
一次编辑,更新所有仪表板:使用 Terraform 大规模管理 Kibana 可观测性配置
elasticsearch
Elasticsearch2 小时前
足够接近就是足够快:ES|QL Fast 模式如何让 Kibana 仪表板速度提升最高 100 倍
elasticsearch
Elasticsearch3 小时前
一分钟内从提示词生成仪表板,成本降低 5 倍:Kibana 中的 AI 仪表板和自定义 Vega-Lite 图表
elasticsearch
Elasticsearch3 小时前
Elastic 9.5: Columnar 、 VectorDB 索引模式与自动校准,以及由 AI 驱动的告警分类整理
elasticsearch
晚安code4 小时前
一、Elasticsearch查询的 DSL 骨架:先把 JSON 看懂
elasticsearch
love530love5 小时前
Ubuntu系统通过Homebrew安装Lightpanda完整实战教程(含端口占用排坑)
大数据·linux·运维·人工智能·elasticsearch·搜索引擎
Elasticsearch15 小时前
将 Embedding 模型加载到 Elasticsearch 中
elasticsearch
Elasticsearch1 天前
使用 Elasticsearch open inference API 对 OpenAI chat completions 进行支持
elasticsearch
Linux运维技术栈1 天前
业务不停机、数据零丢失:Redis / RabbitMQ / Elasticsearch 三大核心中间件升级改造集群无缝平滑迁移
redis·elasticsearch·rabbitmq
Elasticsearch1 天前
15 行点击跟踪代码,告诉你搜索日志无法揭示的信息
elasticsearch