Elastic Search in MySQL
We will learn how to integrate ElasticSearch with MySQL. We will also look at some of the key differences between JSON format databases and relational databases.
Integrating ElasticSearch with MySQL
As we all know, MySQL is a relational-based data management system that stores data in schemas.
On the other hand, Elastic Search (ES) is a NoSQL based data store. It is an open source distributed search engine.
It provides real-time data analysis. Hence it is more efficient than RDBMS in some cases.
It searches websites/applications, collects and analyzes log data, and performs data analysis and visualization. The basic terminology difference between JSON format DB and relational database is: database equals cluster, table equals index (data organization mechanism, storing complex data structures in JSON doc), row equals document, column equals field.
A collection of nodes is called a cluster; shards are pieces of data. The prerequisite here is that we need to install MySQL.
The open source version can be found in the MySQL Community Server section, which you can find at the MySQL download site.
Next, we create a table in MySQL.
CREATE DATABASE info_cus;
DROP TABLE IF EXISTS info_cus;
CREATE TABLE info_cus(
id integer NOT NULL,
PRIMARY KEY (id),
employe_n VARCHAR(32) NOT NULL,
update_time datetime NOT NULL
);
Insert Statement
Now we go to the MySQL server and insert these records:
INSERT INTO info_cus (id, employe_n,update_time)
VALUES (1,'ali',CURDATE()),
(2,'Ayesha',CURDATE()),
(3,'Rizwan',CURDATE()),
(4,'Tanveer',CURDATE());
Now we check:
select * from info_cus;
Output:
id employe_n update_time
1 ali 2022-11-13 15:31:05
2 Ayesha 2022-11-13 15:31:05
3 Rizwan 2022-11-13 15:31:05
4 Tanveer 2022-11-13 15:31:05
If we get the right record sheet, we can start.
Since ES is Java based, we need to download the JDBC connector to connect the two. This connection will help in extracting the required data from the data store and move it to Elastic Search.
To download the JDBC connector, go to this link. There will be a jar file; because it is generic, it should run on any operating system - Windows, macOS, etc.
Next, we extract the files and make sure we use the bin.jar file, no matter what version you have installed, copy this file to the root directory with the name jdbc.jar.
Use the code given below in this new text file. It will create a Logstash pipeline through JDBC plugin.
input {
jdbc {
jdbc_driver_library => "<driverpath>/mysql-connector-java-<versionNumber>.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://<MySQL host>:3306/es_db"
jdbc_user => "<myusername>"
jdbc_password => "<mypassword>"
jdbc_paging_enabled => true
tracking_column => "unix_ts_in__seconds"
use_column_value => true
tracking_column_type => "numeric"
schedule => "*/5 * * * * *"
statement => "select *, unix_timestamp AS unix_ts_in__seconds FROM elas_table where (unix_timestamp > :sql_last_value AND modification_time < NOW()) ORDER BY modification_time ASC"
}
}
filter {
mutate {
copy => { "id" => "[@metadata][_id]"}
remove_field => ["id", "@version", "unix_ts_in__seconds"]
}
}
Output:
{
stdout { codec => "rubydebug"}
}
Now, open it with the new JDBC_conn configuration file Logstash:bin/logstash -f jdbc_conn.conf
. Finally, we go to Logstash to move the data and log in to Elastic Search to authenticate the data in Kibana.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Get the version in MySQL
Publish Date:2025/04/24 Views:169 Category:MySQL
-
In this article, we will learn how to get the current version of MySQL on Windows systems. It is necessary for businesses to maintain versions of different tools and software used to run their business in order to keep systems compatible. T
Full Join in MySQL
Publish Date:2025/04/24 Views:70 Category:MySQL
-
This article aims to explore how to perform a full join or full outer join in MySQL. Full outer join is used to merge or combine the entire data from two separate tables. For example, suppose we have two tables named student_id and student_
Grouping by month in MySQL
Publish Date:2025/04/24 Views:166 Category:MySQL
-
In this article, we will learn how to group values by month in MySQL database. Businesses and organizations have to find user or customer data based on purchase or usage trends over a few months. If a particular business achieves its
Enabling the slow query log in MySQL
Publish Date:2025/04/24 Views:177 Category:MySQL
-
Today, we will enable MySQL in MySQL using MySQL shell on Windows and Ubuntu 20.04 slow_query_log . For this tutorial, we are using MySQL version 8.0 and Ubuntu 20.04. MySQL slow_query_log MySQL slow_query_log contains SQL statements that t
Update multiple tables in MySQL with one query
Publish Date:2025/04/24 Views:65 Category:MySQL
-
In some cases, users want to update logically related tables at the same time. These logically related tables are linked to each other through some attributes. Advantages of updating multiple tables in one MySQL query Similar attributes in
Checking MySQL version in macOS
Publish Date:2025/04/24 Views:60 Category:MySQL
-
In this article, we aim to explore how to check the current version of MySQL on macOS. Checking MySQL version in macOS When trying to figure out the version, you must follow these steps. Each time a person logs into the MySQL server, the ve
Common table expressions in MySQL
Publish Date:2025/04/24 Views:168 Category:MySQL
-
This article aims to understand how to use common table expressions in MySQL. Most data analysts need to store the results of different queries in order to merge them with a separate query. With the help of common tables, expressions can ma
Sorting by date in MySQL
Publish Date:2025/04/24 Views:156 Category:MySQL
-
This article aims to understand how to sort values by date in MySQL. Most of the businesses and organizations that use MySQL for data analysis or data visualization need to sort different table values of their users based on dat
Sort MySQL data alphabetically
Publish Date:2025/04/24 Views:153 Category:MySQL
-
In this article, we aim to explore how to sort data alphabetically in MySQL database. Sorting is the ordering of elements or values in an array or column based on a particular criteria. In this tutorial, we will set the criteria as al