简体   繁体   English

使用Logstash将XML加载到Elasticsearch中

[英]XML load with Logstash into Elasticsearch

I have tried to create a load process with Logstash from an XML file to Elasticsearch. 我试图用Logstash创建一个从XML文件到Elasticsearch的加载过程。

Based on the tutorials i have created the following config file: 根据教程,我创建了以下配置文件:

input {
    file {
        path => [ "D:\data\test\test_invoice.xml" ]
        start_position => "beginning"
        sincedb_path => "nul"
    }
}
filter {
    xml {
        store_xml => "false"
        source => "message"
        #remove_namespaces => "true"
        target => "invoice"
   }
}
output {
    elasticsearch {
        hosts => ["localhost:9200"]
        index => "ofr_invoice"  
    }
    stdout { codec => rubydebug }
}

This is the source XML: 这是源XML:

<?xml version="1.0" encoding="UTF-8" ?>
<invoice>
  <invoice_no>125</invoice_no>
  <vendor>abc</vendor>
  <custormer>asdf</custormer>
  <invoice_items>
    <item>
      <item_name>asdf</item_name>
      <item_price>23</item_price>
    </item>
    <item>
      <item_name>qwer</item_name>
      <item_price>45</item_price>
    </item>
  </invoice_items>
</invoice>

When I have executed it with Logstash I got the following result: 当我用Logstash执行它时,得到以下结果:

Sending Logstash logs to D:/app/elastic/logstash-6.4.0/logs which is now configured via log4j2.properties
[2018-09-14T13:05:38,402][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2018-09-14T13:05:38,889][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.4.0"}
[2018-09-14T13:05:41,796][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2018-09-14T13:05:42,136][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
[2018-09-14T13:05:42,146][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://localhost:9200/, :path=>"/"}
[2018-09-14T13:05:42,280][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
[2018-09-14T13:05:42,323][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2018-09-14T13:05:42,327][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
[2018-09-14T13:05:42,354][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
[2018-09-14T13:05:42,371][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2018-09-14T13:05:42,389][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2018-09-14T13:05:43,811][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x50a295f7 run>"}
[2018-09-14T13:05:43,856][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2018-09-14T13:05:43,874][INFO ][filewatch.observingtail  ] START, creating Discoverer, Watch with file and sincedb collections
[2018-09-14T13:05:44,098][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}

It looks OK, but it did not added the record (document) to Elasticsearch. 看起来不错,但没有将记录(文档)添加到Elasticsearch。 Can anyone tell me why? 谁能告诉我为什么?

I just had the same issue and found the input file path must use forward slashes, so "D:/data/test/test_invoice.xml" instead of "D:\\data\\test\\test_invoice.xml". 我只是遇到了同样的问题,发现输入文件路径必须使用正斜杠,因此使用“ D:/data/test/test_invoice.xml”而不是“ D:\\ data \\ test \\ test_invoice.xml”。

Credit goes to this post on Elastic: https://discuss.elastic.co/t/unable-to-load-xml-file-in-logstash/151318/4 值得一提的是关于Elastic的这篇文章: https : //discuss.elastic.co/t/unable-to-load-xml-file-in-logstash/151318/4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM