我正在尝试学习elasticsearch并将其连接到MySQL数据库。如果我自己使用 elasticsearch,一切正常,但是当尝试从数据库中获取数据时,由于某种原因它似乎不起作用。我是 elasticsearch 和 rivers 的新手,所以我真的无法描述我的问题比这更明确。
为了创建河流,我使用了以下命令:
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"
}
}
} ]
}
}
知道吗?
看起来您没有根据文档进行连接?
不应该是(当然,假设您实际上调用了 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'
看看你是否取得了什么成就。
这做了一些事情现在,如果我运行:
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:nn1) 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.JDBCRivern while locating org.elasticsearch.river.Rivernn1 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]"
}
}
}
]
}
}