elasticsearch - Elastic Filebeat 不会使用映射将自定义索引编入索引
问题描述
我正在尝试将 Filebeats 配置为将事件索引到具有某些字段的自定义映射的自定义命名索引中。问题是 Filebeat 不会将事件发送到我的索引,而是尝试将它们发送到默认的“ filebeats-xxx ”索引,并且由于事件不符合默认的 filebeat 事件格式(即为什么我要使用自己的映射)。
请参阅下面的详细信息。
更新 09/10/2021:在发现此处报告/讨论的类似问题后:https ://github.com/elastic/beats/issues/11866我尝试遵循解决方法并将以下参数添加到 filebeats.yml 以禁用ES 中的 ILM:
setup.ilm.enabled: false
这并没有太大帮助 - filebeat 日志说 ILM 已经设置。所以我又添加了一个参数:
setup.ilm.overwrite: true
在此之后 - 错误停止了,但是当我尝试推送事件时 - filebeat 似乎在以下日志之后挂起:
2021-09-09T21:42:58.057-0400 INFO [publisher_pipeline_output] pipeline/output.go:143 Connecting to backoff(elasticsearch(https://testbeats1.es.us-central1.gcp.cloud.es.io:9243))
2021-09-09T21:42:58.391-0400 INFO [esclientleg] eslegclient/connection.go:273 Attempting to connect to Elasticsearch version 7.14.1
2021-09-09T21:42:58.495-0400 INFO [publisher_pipeline_output] pipeline/output.go:151 Connection to backoff(elasticsearch(https://testbeats1.es.us-central1.gcp.cloud.es.io:9243)) established
我不认为这是一个连接问题,因为日志说连接已建立....知道如何进一步调试它吗?
更新结束
以下是详细信息:
我正在使用 gcp-pubsub 输入类型从 GCP PubSup 主题获取事件。事件被成功接收(通过使用控制台输出确认) - 包含在许多 GCP/filebeat 特定元信息中。如果我向 PubSub 主题发送这样的事件:
{
"referer": "https://blog.zoom.us/",
"activity_ip": "1.1.1.1",
"activity_date": "2021-09-08",
"logstash_id": "m_id_1",
"event_timestamp_millis": "1631126426000",
"cid": "1234567",
"ref_param": "https://www.yahoo.com",
"user_agent": "Mozilla/5.0 (X11; CrOS aarch64 13421.102.0) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/86.0.4240.199 Safari/537.36"
}
Filebeats 收到的实际事件(并在使用控制台输出时打印在控制台上)看起来像这样:
{
"@timestamp": "2021-09-09T15:49:52.948Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "7.14.1",
"_id": "59279bf715-2924539382735950"
},
"message": {
"referer": "https://blog.zoom.us/",
"activity_ip": "1.1.1.1",
"activity_date": "2021-09-08",
"logstash_id": "m_id_1",
"event_timestamp_millis": "1631126426000",
"cid": "1234567",
"ref_param": "https://www.yahoo.com",
"user_agent": "Mozilla/5.0 (X11; CrOS aarch64 13421.102.0) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/86.0.4240.199 Safari/537.36"
},
"input": {
"type": "gcp-pubsub"
},
"ecs": {
"version": "1.10.0"
},
"host": {
"ip": [
"xxxx", ...
],
"mac": [
"...", ...
],
"hostname": "xxx.home",
"architecture": "x86_64",
"os": {
"platform": "darwin",
"version": "10.16",
"family": "darwin",
"name": "Mac OS X",
"kernel": "20.2.0",
"build": "20C69",
"type": "macos"
},
"name": "xxx",
"id": "AB905FFC-D83C-5512-B33A-AA1286026867"
},
"agent": {
"name": "xxx,
"type": "filebeat",
"version": "7.14.1",
"hostname": "xxx",...
},
"event": {
"id": "59279bf715-2924539382735950",
"created": "2021-09-09T15:49:52.936Z"
}
}
我发送的实际事件存储在“消息”元素中。默认情况下,它以字符串形式出现,但由于我发送 JSON 并希望将其视为带有字段/值的 JSON 文档 - 我已将以下 Filebeats 处理器添加到 filebeats.yml:
- decode_json_fields:
fields: ["message"]
(请参阅下面的完整 filebeat.yml 配置)
我还想对事件字段使用我自己的类型 - 例如,对 ip 字段使用“ ip ”类型,对所有特定日期字段使用日期类型等。这就是为什么我想对这些事件使用我自己的映射。并将它们发送到我选择的名称的索引中 - 例如仅用于测试,它是' marina- xxx':
我想出的完整映射/模板在下面指定。起初,我尝试将其作为“ marina_es_template.json ”文件放入 filebeat 根目录并让 Filebeat 上传此映射 - 所以我尝试了以下配置:
setup.template.name: "marina"
setup.template.pattern: "marina-*"
setup.template.json.enabled: true
setup.template.json.path: "marina_es_template.json"
setup.template.json.name: "marina"
setup.template.enabled: true
这不起作用 - filebeat 没有正确上传模板 - 我在我的 ES 中找不到它(使用GET _template/marina * 命令)。所以我已经手动将它加载到我的 ES 中,使用 PUT 命令 - 它工作正常,我可以看到 ES 中列出的模板,并且模板的内容是正确的。
所以,我试图解决的最后一个问题是让 Filebeat 实际上将事件发送到“marina-test1”索引,并将映射正确应用于该索引 - 通过匹配索引名称模式
我为 ES 输出添加了这个配置:
output.elasticsearch:
enabled: true
index: "marina-test2"
并使用此模板设置:
setup.template.name: "marina"
setup.template.pattern: "marina-*"
setup.template.json.enabled: false
并且 Fielbeat 仍然尝试将传入事件发送到“ filebeat- xxx”索引并失败并出现以下错误:
{"type":"mapper_parsing_exception","reason":"failed to parse field [message] of type [text] in document with id '59279bf715-2924626396675533'. ....}
这是正确的,因为在' filebeat '映射中,字段' message '应该是一个文本,而不是一个对象......
所以,问题是:我如何强制 Filebeat 将事件发送到我的“marina-xxx”索引,而不是“filebeat-xxx”索引?
谢谢!
这是我的filebeat.yml :(为清楚起见,删除了评论/未使用的字段
# ============================== Filebeat inputs ===============================
filebeat.inputs:
- type: gcp-pubsub
enabled: true
project_id: my-project
topic: logs-for-es-marina
subscription.name: logs-for-es-marina-sub
credentials_file: /mydir/.config/gcloud/application_default_credentials.json
fields_under_root: true
# ======================= Elasticsearch template setting =======================
setup.template.name: "marina"
setup.template.pattern: "marina-*"
setup.template.enabled: false
## also tried this - but did not help:
#setup.template.json.enabled: true
#setup.template.json.path: "marina_es_template.json"
#setup.template.json.name: "marina"
# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
enabled: true
index: "marina-test2"
hosts: ["https://<my_es>:9243"]
username: "<my-user>"
password: "<my-pwd>"
# ================================= Processors =================================
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
- decode_json_fields:
fields: ["message"]
完整的 ES 模板映射:
PUT _template/marina
{
"index_patterns" :
["marina-*"],
"settings":{
"index": {
"number_of_shards":3,
"number_of_replicas":1
}
},
"mappings":{
"_source":{
"enabled":true
},
"properties" : {
"message": {
"properties":{
"logstash_id":{
"type":"keyword"
},
"event_timestamp_millis":{
"type":"date"
},
"activity_date":{
"type":"date",
"format":"yyyy-MM-dd"
},
"cid":{
"type":"keyword"
},
"activity_ip":{
"type":"ip"
},
"ref_param":{
"type":"text"
},
"referer":{
"type":"keyword"
},
"user_agent":{
"type":"text"
}
}
}
}
}
}
解决方案
这是我自己的答案 - 在我得到这个工作之后:
关键是在 filebeat.yml 中禁用 ILM(索引生命周期管理),如果您之前的实验中有任何挥之不去的模板/索引/别名,请从头开始。
以下两个操作让我进入了一个正常工作的 Filebeat,将 GCP PubSub 中的数据索引到 ES 中的自定义索引中:
停止 Filebeat
清除所有现有的索引/模板(ILM 策略 - 如果您为此索引模式定义了任何内容) - “全部”是指所有相关的,用于您尝试在 ES 中使用的索引和模式;以下命令很有用:
删除 <我的索引名称模式>*
删除 _template/<模板名称>
在filebeat.yml中禁用 ILM - 在“Elasticsearch 模板设置”组中:
setup.ilm.enabled: false
启动 Filebeat
推荐阅读
- javascript - CouchDB Map Reduction 以获取唯一值
- javascript - 如何在 PHP 中 ajax 成功后重置图像文件预览?
- leaflet - LayersControl 内的 react-left FeatureGroup
- java - 使用 spring-boot-starter-mail 时 mailHealthContributor 出现异常
- python - 熊猫滚动标准是如何计算的?
- xslt-1.0 - 计算嵌套子节点的数量
- android - 如何在jetpack compose中为lazyColoumn更改layoutManger(垂直,水平,网格)
- javascript - 样式选项未应用于 html-to-img
- java - Spring字符串到枚举转换器接受空字符串
- css - 你如何让一个css类继承另一个类的所有值而不改变原来的类