1

我正在尝试学习弹性搜索并将其连接到 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"
    }
}
    } ]
  }
}

任何想法?

4

2 回答 2

1

看起来您没有根据文档进行连接?

不应该是(database当然,假设您实际上调用了 DB):

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'

看看你是否取得了什么成就。

于 2014-12-25T15:58:33.210 回答
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]"
                }
            }
        }
    ]
}

}

于 2014-12-25T16:10:33.147 回答