使用 logstash 将 MySQL 中的数据索引到 ElasticSearch 时,仅显示第一行

When using logstash to index data from MySQL to ElasticSearch,only the first row is being displayed

这是我的 logstash 配置文件:

          input
    {
        jdbc 
        {

         jdbc_driver_library => "/home/vatsa/logstash/mysql-connector-java-5.1.38-bin.jar"


         jdbc_driver_class => "com.mysql.jdbc.Driver"

         jdbc_connection_string => "jdbc:mysql://localhost:3306/stud"

         jdbc_user => "root"
         jdbc_password => ""
          statement => "select * from det"
       }
    }
  output  

 {
  elasticsearch 
    {

    index => "det"
    document_type => "contact"
    document_id => "%{uid}"
    hosts => "localhost:9200"
}stdout { codec => json_lines }
}

Logstash 启动和关闭是 created.But 当我使用

进行获取请求时
curl -XGET 'localhost:9200/det/_search?pretty&q=*'

这是输出:

"hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : 
[   {
      "_index" : "det",
      "_type" : "contact",
      "_id" : "%{uid}",
      "_score" : 1.0,
      "_source":{"ID":5,"NAME":"SHUBH","USN":"099","@version":"1","@timestamp":"2016-01-26T05:42:08.362Z"}
    } ]
  }

但是里面有5个实体table.What是这个原因吗??怎么解决??

正如您在索引文档中看到的那样,它的 _id 设置为 "%{uid}",这意味着在您的 SQL table 中您没有任意 uid 字段,可以作为 Elasticsearch 中文档的 ID,因此,字符串 %{uid} 被设置为 ID。

由于每个索引文档都有相同的 ID,它会覆盖具有该 ID 的前一个文档,因此您只能看到一个文档。

尝试确保您的 det SQL table 中有 uid 字段,或者使用正确的 ID 字段作为 document_id 参数在你的 elasticsearch 输出中。也许尝试使用 ID 字段

elasticsearch {
   index => "det"
   document_type => "contact"
   document_id => "%{ID}"             <--- change this ine
   hosts => "localhost:9200"
}