elasticsearch 将数据从MySQL加载到Elasticsearch
您好,我正在使用lostash 2.X版本中的以下scirp文件,我在MySQL数据库表中有186000多条记录,但在运行这个.conf文件时,只有一个文档加载到弹性搜索索引中elasticsearch 将数据从MySQL加载到Elasticsearch,elasticsearch,logstash,elasticsearch,Logstash,您好,我正在使用lostash 2.X版本中的以下scirp文件,我在MySQL数据库表中有186000多条记录,但在运行这个.conf文件时,只有一个文档加载到弹性搜索索引中 input { jdbc { jdbc_connection_string => "jdbc:mysql://localhost/elasticsearch" jdbc_user => "root" jdbc_passwo
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"
}
}
]
}
}
获取mysqltest/\u搜索
{
“查询”:{
“全部匹配”:{}
}
}
{
“take”:14,
“超时”:false,
“_碎片”:{
“总数”:5,
“成功”:5,
“失败”:0
},
“点击次数”:{
“总数”:1,
“最高分数”:1,
“点击次数”:[
{
“_索引”:“mysqltest”,
“_类型”:“mysqltest_类型”,
“_id”:“%{id}”,
“_分数”:1,
“_来源”:{
“partnum”:“,
“财产1”:“财产”,
“财产2”:“财产”,
“颜色”:“,
“大小”:“,
“dim”:“,
“拇指URL”:“,
“catid”:“6575”,
“subcatid”:“3813”,
“termid”:“31999”,
“longdesc”:“- 设备和零件
- GC32-XD零件
- D/V锁紧板螺钉”,
“等级说明”:“重型工具/设备”,
“hier2desc”:“其他重型设备”,
“等级说明”:“软管压接设备和附件”,
“aaiabrandid”:“BBSC”,
“aaiabrandname”:“盖茨”,
“brandimageurl”:“es徽标sm.jpg”,
“行号”:“GAT”,
“描述”:“D/V锁定板螺钉”,
“@version”:“1”,
“@时间戳”:“2016-12-20T09:16:40.075Z”
}
}
]
}
}
好的,您可以看到文档的ID是逐字记录值“%{ID}”
,这意味着您的数据库中显然没有任何ID
列,并且数据库中的所有记录都在同一文档ID下编制索引,因此您只能看到一个文档
在elasticsearch
输出中,需要确保使用作为表主键的字段
document_id => "%{PRIMARY_KEY}"
解决了这个问题,它就会起作用。你能展示你得到的完整文档/结果吗?我已经更新了文档,感谢你的帮助,我的天啊。。。!!!!!你是爱斯瓦尔之神,谢谢你的帮助……我希望每当我发布任何问题时,你都能随时回答。成为你的超级粉丝……我很高兴这对你有帮助。这里有很多非常精明的人随时准备提供帮助;-)