Pages

Wednesday 5 February 2014

Elasticsearch with MySQL using JDBC river


What is River?

A river is a pluggable service running within elasticsearch cluster pulling data (or being pushed with data) that is then indexed into the cluster.
A river is composed of a unique name and a type. The type is the type of the river. The name uniquely identifies the river within the cluster.

What is Plugins?

Plugins are a way to enhance the basic elasticsearch functionality in a custom manner. They range from adding custom mapping types, custom analyzers (in a more built in fashion), native scripts, custom discovery and more.

Installation

Please follow the instructions in the following link to complete the Installation of JDBC river in ElasticSearch.

MySQL  Connection Jar

Download the latest mysql connector from the link and put the jar in elasticsearch/plugins/lib folder.

Example:

PUT Request:

http://localhost:9200/_river/my_jdbc_river/_meta
{
    "type": "jdbc",
    "jdbc": {
        "strategy": "simple",
        "driver": "com.mysql.jdbc.Driver",
        "url": "jdbc:mysql://localhost:3306/test",
        "user": "root",
        "password": "root",
        "sql": "select id as _id, name from testing",
        "poll": "30s",
        "autocommit": true
    },
    "index": {
        "index": "my_jdbc_river",
        "type": "testing"
    }
}
Search Query:

GET Request:

http://localhost:9200/my_jdbc_river/_search?pretty=true

Result:

{
    "took": 3,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [
            {
                "_index": "my_jdbc_river",
                "_type": "testing",
                "_id": "1",
                "_score": 1,
                "_source": {
                    "name": "aswin"
                }
            },
            {
                "_index": "my_jdbc_river",
                "_type": "testing",
                "_id": "2",
                "_score": 1,
                "_source": {
                    "name": "raj"
                }
            }
        ]
    }
}


To know more about the JDBC river click here

                                                              

No comments:

Post a Comment