首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用logstash将json文件中的所有内容发送到elasticsearch

如何使用logstash将json文件中的所有内容发送到elasticsearch
EN

Stack Overflow用户
提问于 2019-04-18 23:55:41
回答 1查看 692关注 0票数 0

我有存储在json文件中的测试结果。然后,我让logstash找到该文件,并尝试将所有行发送到elasticsearch。只有大约一半的行正在被发送,并且无法弄清楚为什么某些行被省略。例如,将有34行,但只发送了14行。

代码语言:javascript
运行
复制
input {
    file {
        path => "/data/*.json"
        start_position => "beginning"
    }
}

# ----------------------------------------------------------------------

filter {

    # Parse fields out of JSON message, then remove the raw JSON. 
    json {
        source => "message"
    }

}

# ----------------------------------------------------------------------

output {
    elasticsearch {
        hosts => ["host:9200", "localhost:9200"]
        index => "ct-%{+YYYY.MM.dd}"
    }
    stdout { codec => rubydebug }

我不确定是json本身有什么原因导致logstash跳过它,还是我在上面发布的logstash.conf文件有问题。

EN

回答 1

Stack Overflow用户

发布于 2019-04-19 16:41:47

Logstash计算不同类型的文件,并将其以Json格式发送到elasticsearch。在您的示例中,具有elasticsearch输出的Filebeat代理足以将json文件发送到ES并对其进行索引。

使用Filebeat 6.x时,它看起来如下所示:

代码语言:javascript
运行
复制
#=========================== Filebeat inputs =============================

filebeat.inputs:

- type: log
  # Paths to the logs
  paths:
    - "/your/path/to/your/logs/file.json"
  # tags to identify the logs source, .gz files excluded from the prospector
  tags: ["beats","yourtag"]
  exclude_files: ['\.gz$']

#================================ Outputs =====================================
#----------------------------- Elasticsearch output --------------------------------
output.elasticsearch:
  # The ES host & index name
  hosts: ["yourEShost:9200"]
  index: "ct-%{+YYYY.MM.dd}"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55749746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档