How to use Elasticsearch next to MySQL? [closed]

3

I want to use elasticsearch to see if I can agility and speed in my MySQL queries.

I started to see a few things, but I found the issue of integration with MySQL a bit confusing, does anyone have any experience with elasticsearch, and can you explain how to integrate elasticsearch with MySQL?

    
asked by anonymous 30.01.2014 / 20:12

1 answer

4

You may need to improve your question a bit by putting more information such as the language your application was written in (I'm talking about the application that currently accesses this database).

Despite this, I'll try to give a generic answer that I hope will help.

Elasticsearch is a distributed search server, REST, free / open source software based on Apache Lucene.

Now, in a very simple way, imagine that it is a black box. You will just put the information you want to store and then you will be able to retrieve it with the id, similar to what you do with Mysql. The main advantage as you yourself have said is that you can do quick textual searches (like google; P).

Another difference is that you do not have a SQL (and at first you do not need schema). To register items in elasticsearch you simply submit a json via the url (HTTP) with the information you want to save and fetch later.

curl -XPUT 'http://localhost:9200/comidas/doce/1' -d '{
    "nome": "Sorvete",
    "descricao": "São deliciosos!",
}'

Similarly, at the time of the search, just pass a url with what you want to fetch (and maybe some options that are not worth discussing here.)

curl -XGET 'http://localhost:9200/comidas/_search?q=descricao:deliciosos'

# Resposta

{
   "took":14,
   "timed_out":false,
   "_shards":{
      "total":5,
      "successful":5,
      "failed":0
   },
   "hits":{
      "total":1,
      "max_score":0.19178301,
      "hits":[
         {
            "_index":"comidas",
            "_type":"doce",
            "_id":"1",
            "_score":0.19178301,
            "_source":{
               "nome":"Sorvete",
               "descricao":"São deliciosos!"
            }
         }
      ]
   }
}

The bottom line is that in the most straightforward solution, you have to save your information (for example, an employee's data) in both mysql and elasticsearch. This would be a responsibility of your application (the same one that uses mysql).

Likewise, when something is changed in the bank (an employee has changed address), you also need to save this data in elasticsearch.

A little annoying, right? To facilitate the work of those who need to have the information of some place inserted automatically also in elasticsearch there are rivers, which are plugins that given a source, automatically "feed" elasticsearch.

There is a specific river for some databases which is link .

With this plugin installed and configured in elasticsearch, as your database is being changed, changes are synchronized with elasticsearch. Hence you only have the job of doing the queries via HTTP in your application.

A tutorial on how to get started with this plugin can be found at link

While this cool plugin does exist, I HIGHLY recommend you try to get to know a bit more about elasticsearch, and it's very helpful to understand what the plugin is doing behind you.

Most of the tutorials (and first steps) of elasticsearch are in English, but I found those of the links in Portuguese that are legal.

31.01.2014 / 17:20