hgerdin
hgerdin

Reputation: 637

Search from jdbc elasticsearch river

I´m trying to learn elasticsearch and connect it to a MySQL database. If I use elasticsearch on it´s own, everything works fine but when trying to fetch data from a database it doesn´t seem to work for some reason. I´m a real novice at elasticsearch and rivers with jdbc so I really can´t describe my problem more defined than this.

For creating a river I used the following command:

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"
    }
}'

When running:

curl -XGET 'localhost:9200/customertest/_search?pretty&q=*'

I get the following answer:

{
  "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"
    }
}
    } ]
  }
}

Any idea?

Upvotes: 1

Views: 254

Answers (2)

hgerdin
hgerdin

Reputation: 637

That did something Now if I run:

localhost:9200/jdbc/_search

I get nothing but if I run:

localhost:9200/_river/customer/_search

I get:

{
"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]"
                }
            }
        }
    ]
}

}

Upvotes: 0

Ashalynd
Ashalynd

Reputation: 12573

Looks like you are not doing the connection according to the docs?

Shouldn't it be (assuming that you have DB actually called database, of course):

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"
    }
}

then try

curl 'localhost:9200/jdbc/_search'

to see if you achieved anything.

Upvotes: 1

Related Questions