2016-12-20 55 views
1

嗨,我在lostash 2.X版本中使用了以下scirp文件我在MySQL數據庫表中有超過186000條記錄,但在運行此.conf文件時,只有一個文檔在彈性搜索索引中加載。從MySQL加載數據到Elasticsearch

input { 
     jdbc { 
      jdbc_connection_string => "jdbc:mysql://localhost/elasticsearch" 
      jdbc_user => "root" 
      jdbc_password => "empower" 
      #jdbc_validate_connection => true 
      jdbc_driver_library => "/home/wtc082/Documents/com.mysql.jdbc_5.1.5.jar" 
      jdbc_driver_class => "com.mysql.jdbc.Driver" 
      statement => "SELECT * FROM index_part_content_local;" 
      #schedule => "* * * * *" 
      #codec => "json" 
     } 
    } 

output { 
    elasticsearch { 
     index => "mysqltest" 
     document_type => "mysqltest_type" 
     document_id => "%{id}" 
     hosts => "localhost:9200" 
    } 
} 

當我使用這個查詢只有一個文檔索引

GET mysqltest/_search 
{ 
    "query": { 
    "match_all": {} 
    } 
} 




{ 
    "took": 14, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 1, 
    "max_score": 1, 
    "hits": [ 
     { 
     "_index": "mysqltest", 
     "_type": "mysqltest_type", 
     "_id": "%{id}", 
     "_score": 1, 
     "_source": { 
      "partnum": "", 
      "property1": "", 
      "property2": "", 
      "color": "", 
      "size": "", 
      "dim": "", 
      "thumburl": "", 
      "catid": "6575", 
      "subcatid": "3813", 
      "termid": "31999", 
      "longdesc": "<ul><li>Equipment and Parts<li>GC32-XD Parts<li>D/V Lock Plate Screw</ul>", 
      "hier1desc": "Heavy Duty Tools/Equipment", 
      "hier2desc": "Other Heavy Duty Equipment", 
      "hier3desc": "Hose Crimping Equipment & Accessories", 
      "aaiabrandid": "BBSC", 
      "aaiabrandname": "Gates", 
      "brandimageurl": "es-logo-sm.jpg", 
      "linecode": "GAT", 
      "descrp": "D/V Lock Plate Screw", 
      "@version": "1", 
      "@timestamp": "2016-12-20T09:16:40.075Z" 
     } 
     } 
    ] 
    } 
} 
+0

你能顯示你得到的全部文件/結果嗎? – Val

+0

我已更新文檔,感謝您提前幫助Val, –

回答

1

好吧,你可以看到你的文檔的ID是逐字值"%{id}",這意味着,顯然你沒有數據庫中的任何id列和數據庫中的所有記錄都使用相同的文檔ID進行索引,因此爲什麼只能看到一個文檔。

在你elasticsearch輸出,你需要確保使用的字段是你的表

document_id => "%{PRIMARY_KEY}" 

的主鍵修復了,這將正常工作。

+0

OMG ... !!!!!你是ES Val的上帝,謝謝你的幫助.....我希望當我發佈任何問題時,你會回答它,eveytime。成爲你的巨大粉絲........ –

+0

我很高興它幫助。周圍有很多非常尖銳的人準備幫忙;-) – Val

相關問題