如何在 ElasticSearch 加载管道中解码 JSON

How to decode JSON in ElasticSearch load pipeline

我在 AWS 上设置了 ElasticSearch,我正在尝试将应用程序日志加载到其中。不同之处在于应用程序日志条目采用 JSON 格式,例如

{"EventType":"MVC:GET:example:6741/Common/GetIdleTimeOut","StartDate":"2021-03-01T20:46:06.1207053Z","EndDate":"2021-03-01","Duration":5,"Action":{"TraceId":"80001266-0000-ac00-b63f-84710c7967bb","HttpMethod":"GET","FormVariables":null,"UserName":"ZZZTHMXXN"} ...}

所以,我正在尝试打开它。 Filebeat docs 提示有 decode_json_fields 处理器;但是,我在 Kinbana 中将消息字段作为单个 JSON 字符串获取;什么都没有打开。

我是 ElasticSearch 的新手,但我不会以此为借口不先做分析。仅作为解释,我不确定哪些信息对回答问题有帮助。

这里是filebeat.yml:

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/opt/logs/**/*.json
processors:
  - add_host_metadata:
    when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~
  - decode_json_fields:
    fields: ["message"]

output.logstash:
    hosts: ["localhost:5044"]

这是 Logstash 配置文件:

input {
    beats {
        port => "5044"
    }
}
output {
    elasticsearch {
        hosts => ["https://search-blah-blah.us-west-2.es.amazonaws.com:443"]
        ssl => true
        user => "user"
        password => "password"
        index => "my-logs"
        ilm_enabled => false
    }
}

我仍在努力理解 Logstash 的过滤和 grok 部分,但 似乎 它应该按原样工作。另外,我不确定实际标签 messages 来自哪里(可能来自 Logstash 或 Filebeat),但它似乎也不相关。

UPDATE:AWS documentation 没有给出仅通过 filebeat 加载而不使用 logstash 的示例。 如果我不使用 logstash(只是 FileBeat)并且在 filebeat.yml 中有以下部分:

output.elasticsearch:
    hosts: ["https://search-bla-bla.us-west-2.es.amazonaws.com:443"]

    protocol: "https"
    #index: "mylogs"

    # Authentication credentials - either API key or username/password.
    #api_key: "id:api_key"
    username: "username"
    password: "password"

我收到以下错误: 如果我使用 index: "mylogs" - setup.template.name 和 setup.template.pattern 如果修改了索引名称则必须设置

如果我不使用索引(那么它在 ES 中会去哪里?)-

Failed to connect to backoff(elasticsearch(https://search-bla-bla.us-west-2.es.amazonaws.com:443)): Connection marked as failed because the onConnect callback failed: cannot retrieve the elasticsearch license from the /_license endpoint, Filebeat requires the default distribution of Elasticsearch. Please make the endpoint accessible to Filebeat so it can verify the license.: unauthorized access, could not connect to the xpack endpoint, verify your credentials

如果通过 logstash 传输一般有效,请按照评论中建议的 Val 添加过滤器块并使用此 json plugin/filter: elastic.co/guide/en/logstash/current/plugins-filters-json.html - 它自动将 json 解析为 elasticsearch 字段