【问题标题】:Search from jdbc elasticsearch river从 jdbc elasticsearch 河中搜索
【发布时间】:2014-12-25 13:09:13
【问题描述】:

我正在尝试学习 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"
    }
}
    } ]
  }
}

有什么想法吗?

【问题讨论】:

  • 您确定安装了 JDBC River 插件吗?例如。将此插件添加到 $ES_HOME/plugins 后,您必须重新启动节点
  • 我如何确定这一点?我已经将插件放在 /usr/local/var/lib/elasticsearch/plugins 中,并且我已经停止并启动了几次节点。
  • 你确定这是正确的输入和输出。您正在访问 jdbc 索引,结果来自 customertest
  • 我已经编辑了我的问题。 :)

标签: mysql jdbc elasticsearch elasticsearch-jdbc-river


【解决方案1】:

您似乎没有按照docs 进行连接?

不应该吗(当然,假设您的数据库实际上称为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'

看看你有没有取得什么成就。

【讨论】:

    【解决方案2】:

    那做了一些事情 现在,如果我运行:

    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-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      相关资源
      最近更新 更多