elasticsearch - ElasticSearch-如何不存储未在静态索引中定义的字段?

标签 elasticsearch

我已经在ES中使用用户实体设置了静态索引

{
    "mappings": {
        "_default_": {
            "dynamic": "false"
        },
        "user": {
            "properties": {
                "id": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "age": {
                    "type": "integer"
                }
            }
        }
    }
}

当我发布的文档中的字段比索引中的字段多时,会将其保存到ES中。
它不会更新映射,但会保存新字段。
有没有一种方法可以删除不在索引中的字段?
我不想存储未索引的字段。

最佳答案

在映射中,您需要使用 _source filtering:

{
  "mappings": {
    "_default_": {
      "dynamic": "false"
    },
    "user": {
      "_source": {
        "includes": [
          "id","name","age"
        ]
      },
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        }
      }
    }
  }
}

关于elasticsearch - ElasticSearch-如何不存储未在静态索引中定义的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39118869/

相关文章:

python - 如何使用python从列表中读取数据并将特定值索引到Elasticsearch中?

elasticsearch - 通过自定义参数进行ElasticSearch无痛脚本过滤

ruby-on-rails - 限制 Rails 中的 Elasticsearch 结果计数

elasticsearch - 需要了解搜索池elasticsearch

python - 如何使用 elasticsearch DSL for python 访问响应对象

node.js - elastic js v5.0文档中没有id时如何自动生成id

elasticsearch - Elasticsearch,当文档存储时,它会分成不同的碎片吗?

elasticsearch - 使用logstash的csv文件输入处理在2/3天后停止工作

elasticsearch - Elasticsearch:范围索引中的数据

java - Elasticsearch 分析