elasticsearch 如何使用Logstash将数据上载到现有索引?,elasticsearch,logstash,elasticsearch,Logstash" /> elasticsearch 如何使用Logstash将数据上载到现有索引?,elasticsearch,logstash,elasticsearch,Logstash" />

elasticsearch 如何使用Logstash将数据上载到现有索引?

elasticsearch 如何使用Logstash将数据上载到现有索引?,elasticsearch,logstash,elasticsearch,Logstash,我试图使用Logstash将.csv文件中的数据插入到已经存在的索引(已经有数据)中 无论如何,这是我的logstash_true.config文件: input { file { path => "pathToFile" start_position => "beginning" sincedb_path => "/dev/null" } } filt

我试图使用Logstash将.csv文件中的数据插入到已经存在的索引(已经有数据)中

无论如何,这是我的logstash_true.config文件:

input {
    file {
        path => "pathToFile"
        start_position => "beginning"
        sincedb_path => "/dev/null"
    }
}

filter {
    csv {
        separator => ","
        columns => ["title", "text", "subject", "date"]
    }

}

output {
    stdout { codec => rubydebug }
    elasticsearch {
        hosts => "127.0.0.1:9200"
        index => "news"
        document_type => "true_news"
        document_id => "%{id}"
    }
}
上传数据时,我可以在命令行中看到文件或数据没有问题,文档类型true\u news实际上存在

但在尝试获取数据时:

{
  "count" : 0,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}
数据没有加载

更新

启用调试时,我收到以下错误:

Could not index event to Elasticsearch. {:status=>400, :action=>
["index", {:_id=>"%{id}", :_index=>"news", :routing=>nil, 
:_type=>"true_news"}, #<LogStash::Event:0x7e10d60f>], :response=>
{"index"=>{"_index"=>"news", "_type"=>"true_news", "_id"=>"%{id}", 
"status"=>400, "error"=>{"type"=>"illegal_argument_exception", 
"reason"=>"Rejecting mapping update to [news] as the final mapping 
would have more than 1 type: [fake_news, true_news]"}}}}
无法将事件索引到Elasticsearch。{:状态=>400,:操作=>
[“索引”、{:_id=>“%{id}”、:_index=>“新闻”、:路由=>nil、,
:_type=>true_news},#],:response=>
{“索引”=>{“{u索引”=>“新闻”,“{u类型”=>“真实新闻”,“{u id”=>“%{id}”,
“状态”=>400,“错误”=>{“类型”=>“非法参数”\u异常”,
“原因”=>“拒绝将更新映射到[新闻]作为最终映射
将有多个类型:[假新闻,真新闻]“}}}

自Elasticsearch 6.0版以来,索引中不能有多种类型

您的索引
news
似乎已经有类型为
fake\u news
的文档或映射,并且您正在尝试插入类型为
true\u news
的文档,这是不可能的,这就是您出现此错误的原因:

"type"=>"illegal_argument_exception", 
"reason"=>"Rejecting mapping update to [news] as the final mapping 
would have more than 1 type: [fake_news, true_news]"

由于您只能有1种类型,并且希望能够区分
true\u news
false\u news
,因此最好重新创建索引,为每个文档使用默认类型
doc
,并使用inpus中的config
add\u tag=>[“tag”]
将带有
true\u news
false\u news
的标记添加到文档中。

启用日志级别的调试并查看日志本身,它应该会告诉您发生了什么。@IDdlerwins在读取日志文件时,我发现了以下错误:
拒绝更新到[news]的映射,因为最终映射将有多个类型
您可以看到整个错误,我更新了问题。错误是因为您尝试索引的内容与索引映射不匹配。您可以删除索引和模式并重新索引所有内容,然后尝试或尝试以下操作:action=>“update”doc\u as\u upsert=>true manage\u template=>false另一种可能的解决方案是将字段格式化为正确的名称和类型。