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

如何通过Mapping阻止Elasticsearch存储指定source字段

解决方案

修改some_index的索引映射,将source字段设置为enabled: false,即可让Elasticsearch忽略传入文档中的整个source字段,不会将其存入数据库,无需修改Java代码。

修改后的完整映射如下:

{
  "_source": {
    "enabled": false
  },
  "properties": {
    "actions": {
      "store": true,
      "type": "integer"
    },
    "identifier": {
      "store": true,
      "type": "keyword"
    },
    "source": {
      "enabled": false
    }
  }
}

原理说明

当字段配置enabled: false时,Elasticsearch会跳过该字段的所有解析和存储操作,不管其内部子字段的原有配置如何。这样即使传入的文档包含source及其子字段,ES也不会保存这些数据,完全符合需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 05:26:27