我正在尝试学习elasticsearch并将其连接到MySQL数据库。如果我自己使用elasticsearch,一切正常,但是当试图从数据库中获取数据时,它似乎不能正常工作。我是一个真正的新手在弹性搜索和河流与jdbc,所以我真的无法描述我的问题比这更明确。
为了创建河流,我使用了以下命令:
curl -XPUT 'localhost:9200/customertest/customer/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/database",
"user" : "root",
"password" : "root",
"sql" : "select * from customers"
}
}'
运行时:
curl -XGET 'localhost:9200/customertest/_search?pretty&q=*'
我得到以下答案:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "customertest",
"_type" : "customer",
"_id" : "_meta",
"_score" : 1.0,
"_source":{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/database",
"user" : "root",
"password" : "root",
"sql" : "select * from customers"
}
}
} ]
}
}
有什么想法吗?
答案 0 :(得分:1)
根据docs?
,您似乎没有进行连接不应该是(假设你实际上有一个DB实际上叫database
):
curl -XPUT 'localhost:9200/_river/customer/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/database",
"user" : "root",
"password" : "root",
"sql" : "select * from customers"
}
}
然后尝试
curl 'localhost:9200/jdbc/_search'
看你是否取得了任何成就。
答案 1 :(得分:0)
那做了些什么 现在,如果我跑:
localhost:9200/jdbc/_search
如果我跑了,我什么也得不到:
localhost:9200/_river/customer/_search
我明白了:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "_river",
"_type": "customer",
"_id": "_meta",
"_score": 1,
"_source": {
"type": "jdbc",
"jdbc": {
"url": "jdbc:mysql://localhost:3306/verendus",
"user": "root",
"password": "root",
"sql": "select * from customers"
}
}
},
{
"_index": "_river",
"_type": "customer",
"_id": "_status",
"_score": 1,
"_source": {
"error": "CreationException[Guice creation errors:\n\n1) Error injecting constructor, java.lang.NoSuchMethodError: org.xbib.elasticsearch.river.jdbc.RiverSource.url(Ljava/lang/String;)Lorg/xbib/elasticsearch/river/jdbc/RiverSource;\n at org.xbib.elasticsearch.river.jdbc.JDBCRiver.<init>(Unknown Source)\n while locating org.xbib.elasticsearch.river.jdbc.JDBCRiver\n while locating org.elasticsearch.river.River\n\n1 error]; nested: NoSuchMethodError[org.xbib.elasticsearch.river.jdbc.RiverSource.url(Ljava/lang/String;)Lorg/xbib/elasticsearch/river/jdbc/RiverSource;]; ",
"node": {
"id": "kMJkU2bvSZuSkbj86u6ziA",
"name": "Black Dragon",
"transport_address": "inet[/127.0.0.1:9300]"
}
}
}
]
}
}