Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use elasticsearch combined with mysql for full-text search

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use elasticsearch combined with mysql for full-text search". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use elasticsearch combined with mysql for full-text search"!

Elasticsearch download and installation start

First of all, go to the official website to download the installation package.

There is a compression package zip for Windows and an installation bootstrap such as msi. After decompression or installation, go to the bin directory and run elasticsearch.bat;, and then access it in the browser. The result of successful startup is as follows:

If you want to configure multiple nodes on a single host for testing, you may modify the configuration file

Download the head plug-in

Since this article is aimed at ES6.x, node and grunt environments are required to install head in ES version 5.x and above (previously, you can install it directly with the plugin command), so you should install Node on the premise. The complete steps are as follows:

Go to the official website to download the Node installation package and install it directly according to the prompts. The following prompts indicate that the installation is successful.

The directory after installation is shown below:

Note here: the new version of Node.js comes with npm, which is installed with Node.js. The function of npm is to manage the packages that Node.js depends on, and it can also be understood to be used to install / uninstall what Node.js needs to install.

Environment configuration

The environment configuration here mainly configures the path where the global module installed by npm is located, as well as the path of caching cache. The reason for configuration is that when you execute an installation statement similar to: npm install express [- g] (the optional parameter-global g represents the global installation of global), the installed module will be installed to the [C:\ Users\ user name\ AppData\ Roaming\ npm] path, occupying the space of disk C.

For example, if I want to put the path and cache path of the whole module in the folder where I installed node.js, then create two folders [node_global] and [node_cache] under my installation folder [D:\ nodejs] as shown below:

After you have created two empty folders, open the cmd command window and type

Next, set the environment variable, close the cmd window, "my computer"-right-click-"Properties"-"Advanced system Settings"-"Advanced"-"Environment variable", enter the environment variable dialog box, create a new [NODE_PATH] under [system variable], enter [D:\ nodejs\ node_global\ node_modules], and change [Path] under [user variable] to [D:\ nodejs\ node_global].

test

After the configuration, install a module test, we will install the most commonly used express module, open the cmd window

Enter the following command to install the module globally:

Description: when installing modules through npm, they are downloaded from foreign images. Sometimes the installation module will fail due to network reasons. Fortunately, Ali has a team to maintain the domestic image: http://npm.taobao.org/ has instructions for use.

There are two ways to modify the image:

Command Lin

Npm changes the default global path and cache path

New path of npm config set prefix

New path of npm config set cache

Npm config set registry https://registry.npm.taobao.org

Configuration file mode

Add a file under the user's home directory. npmrc

Install head and visit https://github.com/mobz/elasticsearch-head to download the head plug-in (choose the zip package download method).

Modify ~\ elasticsearch-6.6.2\ elasticsearch-head-master\ Gruntfile.js and add the hostname:'*' configuration item in the corresponding location.

Execute npm install under ~\ elasticsearch-6.6.2\ elasticsearch-head-master to start the installation, and then execute grunt server or npm run start to run the head plug-in. (here there may be failures due to network reasons. You can try again after the network is unblocked. I have tried again four or five times.)

Install successfully, visit http://localhost:9100/.

The link to ES here may not be successful. Because of the cross-domain problem of Access-Control-Allow-Origin, you can add the following code to the end of the ~\ config\ elasticsearch.yml file of ElasticSearch 6.x, and restart ES after configuration.

Install the Logstash and Logstash-input-jdbc plug-ins

Go to the official website and now Logstash the corresponding version. You can decompress and install it directly.

Start and verify, open the CMD window and change to the bin directory to execute

If you start up normally, you will see (you can enter the test content, such as "hello world" for further verification)

Install the Logstash-input-jdbc plug-in

Also executed in the bin directory, the successful message will be printed if the installation is normal.

Verify Logstash-input-jdbc

Take mysql as an example, download the driver jar to the local directory, and then write the configuration file

Run the test

The following jdbc program appears to prove that the mysql data has been entered into ES and is ready for full-text search

At this point, I believe you have a deeper understanding of "how to use elasticsearch combined with mysql for full-text search". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report