gpt4 book ai didi

java - Elasticsearch - 默认情况下不映射字段

转载 作者:搜寻专家 更新时间:2023-11-01 03:05:27 25 4
gpt4 key购买 nike

在索引文档时,Elasticsearch 会自动为缺失的字段(在文档内)创建映射

是否可以配置(或)是否有一个配置,我们可以指示 elasticsearch 不要创建缺失的字段,而是忽略。

基本上,我们使用 Java POJO,我们使用相同 POJO 的实例来索引文档(通过使用 GSON 库将此实例转换为 json),并将此 POJO 中的一些字段用于某些外部目的。

因此,当我们设置那些用于外部用途的字段,但将文档发送到 Elasticsearch 时,这些额外的字段也会被保存。我们希望避免这种情况。

最佳答案

是的,可以在 Elasticsearch 中禁用动态映射功能,以便在摄取新字段时不会动态创建映射。来自文档:

Dynamic mapping

When Elasticsearch encounters a previously unknown field in a document, it uses dynamic mapping to determine the datatype for the field and automatically adds the new field to the type mapping.

Sometimes this is the desired behaviour and sometimes it isn’t. Perhaps you don’t know what fields will be added to your documents later on, but you want them to be indexed automatically. Perhaps you just want to ignore them. Or — especially if you are using Elasticsearch as a primary datastore — perhaps you want unknown fields to throw an exception to alert you to the problem.

Fortunately, you can control this behaviour with the dynamic setting, which accepts the following options:

  • true - Add new fields dynamically — the default

  • false - Ignore new fields

  • strict - Throw an exception if an unknown field is encountered

https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html

关于java - Elasticsearch - 默认情况下不映射字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24448080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com