Elasticsearch how to retrieve table values from mysql and PHP


(Satheesh Kumar) #1

I have installed Elastisaerch and MySQL jdbc driver in my localhost. I have verified it was working fine. After that I have updated the database and table properties using below parameters.

{
    "type" : "jdbc",
    "jdbc" : {
        "driver" : "com.mysql.jdbc.Driver",
        "url" : "jdbc:mysql://localhost:3306/elastisearch",
        "user" : "elastic",
        "password" : "pass@123",
        "sql" : "select `mytable`.`id` as `_id`, `mytable`.`firstname`, `mytable`.`lastname` from mytable",
        "poll" : "1h",
        "scale" : 0,
        "autocommit" : false,
        "fetchsize" : 100,
        "max_rows" : 0,
        "max_retries" : 3,
        "max_retries_wait" : "10s",
        "locale" : "in",
        "digesting" : true 
    }
}

this was updated by using curl -XPOST http://localhost:9200/myindex/mytype/_meta and i received below message

 {
  "_index": "myindex",
  "_type": "mytype",
  "_id": "_meta",
  "_version": 1,
  "created": true
}

I have verified in command prompt with below code

curl -XGET localhost:9200/myindex/_search?pretty

and I received below message

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "myindex",
      "_type" : "mytype",
      "_id" : "_meta",
      "_score" : 1.0,
      "_source":{
    "type" : "jdbc",
    "jdbc" : {
        "driver" : "com.mysql.jdbc.Driver",
        "url" : "jdbc:mysql://localhost:3306/elastisearch",
        "user" : "elastic",
        "password" : "Ppts@123",
        "sql" : "select `mytable`.`id` as `_id`, `mytable`.`firstname`, `mytable
`.`lastname` from mytable",
        "poll" : "1h",
        "scale" : 0,
        "autocommit" : false,
        "fetchsize" : 100,
        "max_rows" : 0,
        "max_retries" : 3,
        "max_retries_wait" : "10s",
        "locale" : "in",
        "digesting" : true
    }
}
    } ]
  }
}

I need to check the values with some search queries how can i check the results with Elastic-search? please give me one sample to view the value in MySQL table.


(Mark Walkom) #2

You can't just add that to ES and expect it to connect to a database.

You need to use the Logstash JDBC input.


(system) #3