gpt4 book ai didi

elasticsearch - Elasticsearch 5.x.x无法禁用动态映射

转载 作者:行者123 更新时间:2023-12-02 22:38:30 25 4
gpt4 key购买 nike

我试图对索引创建时未在映射中明确定义的任何字段禁用动态映射。什么都行不通,所以我什至在他们的文档中尝试了该示例

PUT my_index
{
"mappings": {
"my_type": {
"dynamic": false,
"properties": {
"user": {
"type": "text"
}
}
}
}
}

做了一个测试插入:
POST my_index/my_type
{
"user": "tester",
"some_unknown_field": "lsdkfjsd"
}

然后搜索索引显示:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "AViPrfwVko8c8Q3co8Qz",
"_score": 1,
"_source": {
"user": "tester",
"some_unknown_field": "lsdkfjsd"
}
}
]
}
}

我期望“some_unknown_field”不会被索引,因为它没有在映射中定义。那么为什么仍要对其进行索引?我想念什么吗?

更新

事实证明,在5.0.0版本中当前无法实现我想要的功能,因此我在发送到elasticsearch之前删除了应用程序中的字段,并获得了相同的最终结果。

最佳答案

使用mapping创建索引时,映射的作用是使您的字段为您提到的类型。因此,对于在映射过程中未提及任何内容然后尝试插入值的字段,ES始终将其视为新字段,并使用default mapping将其添加到索引中。因此,如果您不想在_source中看到特定字段,可以执行一些source filtering

解决方法:

  • 如果不是这种情况,请尝试在以下情况下禁用default mapping
    您正在创建索引。
  • 尝试将dynamic属性转换为strict:
    PUT /test
    {
    "settings": {
    "index.mapper.dynamic": false
    },
    "mappings": {
    "testing_type": {
    "dynamic":"strict",
    "properties": {
    "field1": {
    "type": "string"
    }
    }
    }
    }
    }

  • 如果以上两个方法均无法解决,请尝试将 index_mapper_dynamic设置为false。这个 SO可能很方便。希望能帮助到你。

    关于elasticsearch - Elasticsearch 5.x.x无法禁用动态映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40756905/

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