如何将 ElasticSearch 与 MySQL 集成?
本文介绍了如何将 ElasticSearch 与 MySQL 集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的一个项目中,我计划将 ElasticSearch 与 MySQL 结合使用.我已经成功安装了 ElasticSearch.我可以单独管理 ES 中的索引.但我不知道如何在 MySQL 中实现相同的功能.
In one of my project, I am planning to use ElasticSearch with MySQL.
I have successfully installed ElasticSearch. I am able to manage index in ES separately. but I don’t know how to implement the same with MySQL.
我已经阅读了一些文档,但我有点困惑,没有一个清晰的想法.
I have read a couple of documents but I am a bit confused and not having a clear idea.
推荐答案
我终于找到了答案.分享我的发现.
Finally i was able to find the answer. sharing my findings.
要在 Mysql 中使用 ElasticSearch,您需要 Java 数据库连接 (JDBC) 导入器.使用 JDBC 驱动程序,您可以将 mysql 数据同步到 elasticsearch.
To use ElasticSearch with Mysql you will require The Java Database Connection (JDBC) importer. with JDBC drivers you can sync your mysql data into elasticsearch.
我使用的是 ubuntu 14.04 LTS,您需要安装 Java8 才能运行用 Java 编写的 elasticsearch
I am using ubuntu 14.04 LTS and you will require to install Java8 to run elasticsearch as it is written in Java
以下是安装ElasticSearch 2.2.0和ElasticSearch-jdbc 2.2.0的步骤,请注意两个版本必须相同
following are steps to install ElasticSearch 2.2.0 and ElasticSearch-jdbc 2.2.0 and please note both the versions has to be same
安装Java8后…..如下安装elasticsearch 2.2.0
after installing Java8 ….. install elasticsearch 2.2.0 as follows
# cd /opt
# wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.2.0/elasticsearch-2.2.0.deb
# sudo dpkg -i elasticsearch-2.2.0.deb
此安装过程会将 Elasticsearch 安装在/usr/share/elasticsearch/中,其配置文件将放置在/etc/elasticsearch 中.
This installation procedure will install Elasticsearch in /usr/share/elasticsearch/ whose configuration files will be placed in /etc/elasticsearch .
现在让我们在配置文件中做一些基本的配置.这里/etc/elasticsearch/elasticsearch.yml 是我们的配置文件您可以通过
Now lets do some basic configuration in config file. here /etc/elasticsearch/elasticsearch.yml is our config file
you can open file to change by
nano /etc/elasticsearch/elasticsearch.yml
并更改集群名称和节点名称
and change cluster name and node name
例如:
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: servercluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: vps.server.com
#
# Add custom attributes to the node:
#
# node.rack: r1
现在保存文件并启动elasticsearch
Now save the file and start elasticsearch
/etc/init.d/elasticsearch start
测试ES安装或不运行以下
to test ES installed or not run following
curl -XGET 'http://localhost:9200/?pretty'
如果你得到关注,那么你的elasticsearch现在已经安装:)
If you get following then your elasticsearch is installed now