Templates 尽管动态映射被停用,Logstash仍继续创建字段
我已经定义了自己的模板供logstash使用,其中我已停用动态映射:Templates 尽管动态映射被停用,Logstash仍继续创建字段,templates,elasticsearch,mapping,logstash,Templates,elasticsearch,Mapping,Logstash,我已经定义了自己的模板供logstash使用,其中我已停用动态映射: { "my_index": { "order": 0, "template": "my_index", "settings": { "index": { "mapper": { "dynamic": "false" },
{
"my_index": {
"order": 0,
"template": "my_index",
"settings": {
"index": {
"mapper": {
"dynamic": "false"
},
"analysis": {
"analyzer": {
"nlp_analyzer": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "nlp_tokenizer"
}
},
"tokenizer": {
"nlp_tokenizer": {
"pattern": ""
"(\w+)|(\s*[\s+])"
"",
"type": "pattern"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "0"
}
},
"mappings": {
"author": {
"properties": {
"author_name": {
"type": "keyword"
},
"author_pseudo": {
"type": "keyword"
},
"author_location": {
"type": "text",
"fields": {
"standard": {
"analyzer": "standard",
"term_vector": "yes",
"type": "text"
},
"nlp": {
"analyzer": "nlp_analyzer",
"term_vector": "yes",
"type": "text"
}
}
}
}
}
}
}
}
为了测试elasticsearch是否不会生成新字段,我尝试在我的事件中设置一个映射中不存在的字段,假设我有此事件:
{
“type” => “author”,
“author_pseudo” => “chloemdelorenzo”,
“author_name” => “Chloe DeLorenzo”,
“author_location” => “US”,
}
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
为该事件编制索引时,Elasticsearch将在映射中生成一个新字段:
{
“type” => “author”,
“author_pseudo” => “chloemdelorenzo”,
“author_name” => “Chloe DeLorenzo”,
“author_location” => “US”,
}
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
我知道Logstash正在使用我的模板,因为在我的映射中,我使用了一个自定义分析器,我可以在生成的映射中找到它。但显然它没有考虑到动态场被禁用
我希望elasticsearch忽略映射中不存在的字段,但为具有已定义映射的字段编制索引。如何避免日志存储以创建新字段?此答案与您的要求不完全一致,但您可以使用如下日志存储筛选器手动删除字段:
filter {
mutate {
remove_field => ["fieldname"]
}
}
如果您的事件具有已定义的字段列表,则可以通过这种方式解决问题。您应该在文档类型级别强制执行映射 无论此设置的值如何,仍然可以添加类型 在创建索引或使用PUT映射API时显式执行 因此,您的映射将如下所示:
"mappings": {
"author": {
"dynamic": false,
"properties": {
"author_name": {
"type": "keyword"
},
"author_pseudo": {
"type": "keyword"
},
"author_location": {
"type": "text",
"fields": {
"standard": {
"analyzer": "standard",
"term_vector": "yes",
"type": "text"
},
"nlp": {
"analyzer": "nlp_analyzer",
"term_vector": "yes",
"type": "text"
}
}
}
}
}
}
是的,我知道,但是我可能会遇到很多意想不到的字段,所以这是一个我负担不起的解决方案,
prune
过滤器呢?它允许您将好的字段列入白名单,而不是将其列入黑名单。检查我想我找到了一个解决方案,而不使用其他插件。我在文档类型级别强制执行动态映射:…“author”:{“dynamic”:“false”,“properties”:{…