gpt4 book ai didi

elasticsearch - 使用 logstash 创建自定义 elasticsearch 索引

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

我必须使用 logstash 在 elasticsearch 中创建自定义索引。我在 elasticsearch 中创建了新模板,在 logstash 配置中我指定了模板路径、template_name 和 template_overwrite 值,但是每当我运行 logstash 时,新索引都是使用 logstash-dd-mm-yy 正则表达式生成的,而不是属性中指定的 template_name ,logstash -config 文件是

input {
file {
path => "/temp/file.txt"
type => "words"
start_position => "beginning"
}
}
filter {

mutate {
add_field => {"words" => "%{message}"}
}

}
output {
elasticsearch {
hosts => ["elasticserver:9200"]
template => "pathtotemplate.json"
template_name => "newIndexName-*"
template_overwrite => true
}
stdout{}
}

索引模板文件是

{
"template": "dictinary-*",
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0,
"index" : {
"query" : { "default_field" : "@words" },
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
"mappings": {
"_default_": {
"_all": { "enabled": false },
"_source": { "compress": true },
"dynamic_templates": [
{
"string_template" : {
"match" : "*",
"mapping": { "type": "string", "index": "not_analyzed" },
"match_mapping_type" : "string"
}
}
],
"properties" : {
"@fields": { "type": "object", "dynamic": true, "path": "full" },
"@words" : { "type" : "string", "index" : "analyzed" },
"@source" : { "type" : "string", "index" : "not_analyzed" },
"@source_host" : { "type" : "string", "index" : "not_analyzed" },
"@source_path" : { "type" : "string", "index" : "not_analyzed" },
"@tags": { "type": "string", "index" : "not_analyzed" },
"@timestamp" : { "type" : "date", "index" : "not_analyzed" },
"@type" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}

请帮忙

最佳答案

要执行您想要的操作,您必须在 Elasticsearch 输出 block 中设置 index 参数。您的输出 block 将如下所示:

output {
elasticsearch {
hosts => ["elasticserver:9200"]
index => "newIndexName-%{+YYYY.MM.dd}"
template => "pathtotemplate.json"
template_name => "newIndexName-*"
template_overwrite => true
}
stdout{}
}

关于elasticsearch - 使用 logstash 创建自定义 elasticsearch 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39938074/

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