You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何更新Elasticsearch索引映射,添加normalizer及phonetic子字段

Elasticsearch索引映射更新步骤

1. 先配置所需的归一化器和分析器

如果你的索引还没定义keyword_lowercase归一化器和phonetic_analyzer分析器,得先更新索引的settings。执行这条命令:

PUT /your_index_name/_settings
{
  "analysis": {
    "normalizer": {
      "keyword_lowercase": {
        "type": "custom",
        "filter": ["lowercase"]
      }
    },
    "analyzer": {
      "phonetic_analyzer": {
        "tokenizer": "standard",
        "filter": ["lowercase", "phonetic"]
      }
    }
  }
}

注意:如果集群没装phonetic插件,先执行安装命令:bin/elasticsearch-plugin install analysis-phonetic(根据ES版本和部署方式调整)。

2. 更新name字段的映射

用PUT _mapping命令添加keyword子字段的normalizer,同时新增phonetic子字段:

PUT /your_index_name/_mapping
{
  "properties": {
    "name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256,
          "normalizer": "keyword_lowercase"
        },
        "phonetic": {
          "type": "text",
          "analyzer": "phonetic_analyzer"
        }
      }
    }
  }
}

3. 重新索引已有数据(必做)

更新映射后,旧数据不会自动应用新的配置,得重新索引让设置生效。可以用两种方式操作:

方式一:新建索引重导数据

POST _reindex
{
  "source": {
    "index": "your_index_name"
  },
  "dest": {
    "index": "your_index_name_new"
  }
}

重导完成后,删除旧索引,将新索引改名为原索引名即可。

方式二:原地更新数据

POST /your_index_name/_update_by_query?conflicts=proceed

验证映射是否生效

执行这条命令查看当前索引的映射:

GET /your_index_name/_mapping

内容的提问来源于stack exchange,提问作者DSM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 07:35:25