gpt4 book ai didi

elasticsearch - Elasticsearch 模板中未应用副本和分片设置

转载 作者:行者123 更新时间:2023-11-29 02:57:25 25 4
gpt4 key购买 nike

我添加了一个这样的模板:

curl -X PUT "e.f.g.h:9200/_template/impression-template" -H 'Content-Type: application/json' -d'
{
"index_patterns": ["impression-%{+YYYY.MM.dd}"],
"settings": {
"number_of_shards": 2,
"number_of_replicas": 2
},
"mappings": {
"_doc": {
"_source": {
"enabled": false
},
"dynamic": false,
"properties": {
"message": {
"type": "object",
"properties": {
...

我有 logstash 实例,它从 kafka 读取事件并将它们写入 ES。这是我的 logstash 配置:

input {
kafka {
topics => ["impression"]
bootstrap_servers => "a.b.c.d:9092"
}
}
filter {
json {
source => "message"
target => "message"
}
}
output {
elasticsearch {
hosts => ["e.f.g.h:9200"]
index => "impression-%{+YYYY.MM.dd}"
template_name => "impression-template"
}
}

但每天我都会得到包含 5 个分片和 1 个副本的索引(这是 ES 的默认配置)。我该如何解决这个问题,以便获得 2 个副本和 2 个分片?

最佳答案

不确定是否可以添加 index_pattern作为my_index-%{+YYYY.MM.dd} ,因为当你创建它时 PUT my_index-2019.03.10它将具有空映射,因为它未被识别。我有同样的问题,解决方法是设置 index_pattern作为my_index-*并为应该类似于 my_index-2017, my_index-2018... 的索引添加年份后缀

{
"my_index_template" : {
"order" : 0,
"index_patterns" : [
"my_index-*"
],
"settings" : {
"index" : {
"number_of_shards" : "5",
"number_of_replicas" : "1"
}
},...

我从时间戳字段中取出年份部分 (YYYY-MM-dd)生成 year并通过 logstash 将其添加到索引名称的末尾

grok {
match => [
"timestamp", "(?<index_year>%{YEAR})"
]
}

mutate {
add_field => {
"[@metadata][index_year]" => "%{index_year}"
}
}

mutate {
remove_field => [ "index_year", "@version" ]
}
}
output{
elasticsearch {
hosts => ["localhost:9200"]
index => "my_index-%{[@metadata][index_year]}"
document_id => "%{some_field}"
}
}

logstash 之后完成了,我设法得到了my_index-2017 , my_index-2018my_index-2019具有 5 个分片和 1 个副本的索引以及我在模板中预定义的正确映射。

关于elasticsearch - Elasticsearch 模板中未应用副本和分片设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56862992/

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