Elasticsearch learning Trilogy 2: quickly build the environment

Keywords: ElasticSearch

Elasticsearch learning Trilogy 2: quickly build the environment

docker installing elasticsearch

Little experience

Why install version 7.6.2?

The reason is that the subsequent integration of springboot is 2.3.1.RELEASE, which depends on es version 7.6.2, so it is consistent

Pull image

docker pull elasticsearch:7.6.2

Start mirroring

docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:7.6.2

Explanation of some parameters for startup

ES_JAVA_OPTS="-Xms512m -Xmx512m" most small partners should install these services on the virtual machine. Maybe the memory of the virtual machine is not very large, and the ES startup requires 2G memory by default, so the default memory is reduced

In the "discovery. Type = single node" learning stage, there is no need to build a cluster. Set it as a single node and skip some checks

Installation inspection

Browser input http://localhost:9200/ The figure below shows that the installation is complete

docker installing elasticsearch head

Pull image

docker pull mobz/elasticsearch-head:5

Start mirroring

docker run -d --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5

Installation inspection

Browser input http://localhost:9100/ The figure below shows that the installation is complete

Note: elasticsearch cannot be connected at this time due to cross domain problems

Configure the connection between elasticsearch head and elasticsearch

Enter container

docker exec -it elasticsearch /bin/bash

Modify configuration

vi config/elasticsearch.yml

Add these two lines at the bottom of the configuration (allow cross domain access)

http.cors.enabled: true 
http.cors.allow-origin: "*"

Exit container after saving

exit

Restart container

docker restart elasticsearch

Browser input again http://localhost:9100/ , enter in the address bar before the connect button http://localhost:9200 , after clicking connect, the following figure shows that the connection configuration is completed

Request 406 exception while resolving elasticsearch head operation

Copy the files in elasticsearch head to local

docker cp elasticsearch-head:/usr/src/app/_site/vendor.js /usr/local/

Modify vendor.js

vim /usr/local/vendor.js

There are two places in total, in line 6886 and line 7573 respectively. The value of contentType in these two places is changed to application/json;charset=UTF-8

copy from local to container

docker cp /usr/local/vendor.js elasticsearch-head:/usr/src/app/_site

Restart container

docker restart elasticsearch-head

Try to create an index in the head. A pop-up window indicates success

elasticsearch installs the id word breaker plug-in

Mode 1: online installation

Enter container

docker exec -it elasticsearch /bin/bash

Download and install online

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip

When the above operation times out, change github.com to github.com.cnpmjs.org and try again

Exit the container and restart

exit
docker restart elasticsearch

Mode 2: offline installation

Download offline package

Download elasticsearch-analysis-ik-7.6.2. I downloaded it through accelerated access, and the security is not guaranteed

Original access address:

https://github.com/medcl/elasticsearch-analysis-ik/releases

Accelerated access address:

https://github.com.cnpmjs.org/medcl/elasticsearch-analysis-ik/releases

It is recommended to use the original access address first. When the original access address cannot be downloaded, then use the accelerated method

Upload offline package to server

It uploads by itself, because the Docker Desktop I use is directly local

Start installation

Enter container

docker exec -it elasticsearch /bin/bash

create folder

mkdir /usr/share/elasticsearch/plugins/ik

Exit the container and copy the local package into the container

docker cp /usr/local/elasticsearch-analysis-ik-7.6.2.zip elasticsearch:/usr/share/elasticsearch/plugins/ik

Re enter the container

docker exec -it elasticsearch /bin/bash

Unzip the uploaded package

unzip elasticsearch-analysis-ik-7.6.2.zip

Delete original package

rm -rf elasticsearch-analysis-ik-7.6.2.zip

Exit the container and restart

exit
docker restart elasticsearch

Verify after installation

IK word breaker custom word segmentation

Enter container

docker exec -it elasticsearch /bin/bash

Enter ik configuration

cd /usr/share/elasticsearch/plugins/ik/config

Modify IKAnalyzer.cfg.xml

vi IKAnalyzer.cfg.xml

IKAnalyzer.cfg.xml is as follows

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <comment>IK Analyzer Extended configuration</comment>
    <!--Users can configure their own extended dictionary here -->
    <entry key="ext_dict">ext.dic</entry>
     <!--Users can configure their own extended stop word dictionary here-->
    <entry key="ext_stopwords"></entry>
    <!--Users can configure the remote extension dictionary here -->
    <!-- <entry key="remote_ext_dict">words_location</entry> -->
    <!--Users can configure the remote extended stop word dictionary here-->
    <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

Create a new ext.dic file in the config directory

vi ext.dic

For example: add the string "I grass"

Exit the container and restart

exit
docker restart elasticsearch

Verify word segmentation results

Posted by carlmcdade on Wed, 27 Oct 2021 23:35:21 -0700