A, aboutElasticsearch
The understanding of the
-
What is Elasticsearch
ElasticSearch is a Lucene-based search server. It provides a distributed multi – user – capable full – text search engine based on RESTful Web interface. Elasticsearch, developed in Java and released as open source under the Apache license, is a popular enterprise-level search engine. Designed for use in cloud computing, real-time search is possible. Stable, reliable, fast, easy to install and use.
ElasticSearch is a Restful interface based database similar to mysql and more specifically mongodb document database
-
2. Several ways to search for data
- Direct use of
mysql
theLIKE
Fuzzy query (not recommended) - Full-text search using databases (slow search)
- use
ElasticSearch
- Direct use of
Second, about theElasticSearch
Several concepts in
-
Cluster (cluster)
Represents a cluster in which there are multiple nodes, one of which is the primary node, which is elected (the primary and secondary nodes are within the cluster). One concept of ElasticSearch is decentralization, which literally means node-less. This is for the outside of the cluster, because the ElasticSearch cluster is logically whole from the outside, and your communication with any one node is equivalent to that with the entire ES cluster.
-
The index (index)
You can create one or more indexes in ElasticSearch. We can write documents to or read documents from an index (metaphorically, we can insert and read data from a database)
-
The document (the document)
A document can be understood simply as a table in a database, which is the entity on which ElasticSearch ultimately operates
-
Mapping (mapping)
Plain documents are analyzed before being indexed. How do you separate the input text into terms and which terms are filtered, a practice called mapping
-
Type (type)
Each document has a corresponding type, which allows users to store multiple document types in a single index without providing different document types and different mappings
-
Shard (shards)
ElasticSearch can split a complete index into multiple shards. This allows you to split a large index into multiple shards and distribute them on different nodes. Constitute a distributed search. The number of shards can only be specified before the index is created, and cannot be changed after the index is created
Three,docker
The installationElasticsearch
-
1. Install the image of the latest version directly
docker pull elasticsearch Copy the code
-
2. Start the image
docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch Copy the code
-
3. Enter the browser to test whether the container is successfully started
http://localhost:9200 Copy the code
{ name: "N9kE1aI", cluster_name: "elasticsearch", cluster_uuid: "4B0Z7qa2QjSbsRB1JMTZzw", version: { number: "5.6.12." build_hash: "cfe3d9f", build_date: "The 2018-09-10 T20: when 732 z", build_snapshot: false, lucene_version: "6.6.1" }, tagline: "You Know, for Search" } Copy the code
-
4. Deal with cross-domain issues
# Enter the container docker Exec it [container ID] /bin/bash Go to the directory cd config Write file echo 'http.cors.allow-origin: "*"' >> elasticsearch.yml echo "http.cors.enabled: true" >> elasticsearch.yml # View file contents cat elasticsearch.yml # Exit container exit Copy the code
-
5. Restart the container
docker Restart [container ID] Copy the code
4. Install Chinese word segmentation plug-in
-
1. Official website address
-
2. Download address
-
3. Copy the downloaded file to the Docker container
docker Cp/directory/elasticsearch - analysis - ik - 7.11.2. Zip container ID: / usr/share/elasticsearch/plugins Copy the code
-
4. Enter the container
-
5, in the/usr/share/elasticsearch/plugins/directory to create a folder ik, and move the word segmentation software just copy to ik directory
# create file mkdir ik # move file mv Elasticsearch - analysis - ik - 7.11.2.zip ik Copy the code
-
6. Unzip and delete files
unzip Elasticsearch - analysis - ik - 7.11.2. Zip Delete the compressed package rm - rf elasticsearch - analysis - ik - 7.11.2. Zip Copy the code
-
7. Exit the container and restart it.
-
Docker elasticSearch is not the same as docker elasticSearch
-
View the ElasticSearch version
# Check the version of ElasticSearch that is already installed docker image inspect elasticsearch:latest | grep -i version Copy the code
"JAVA_VERSION=8u181", "JAVA_DEBIAN_VERSION=8u181-b13-1~deb9u1", "CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1", "GOSU_VERSION=1.10 ", "ELASTICSEARCH_VERSION=5.6.12." "ELASTICSEARCH_DEB_VERSION=5.6.12. "" "DockerVersion": "17.06.2 - ce", "JAVA_VERSION=8u181", "JAVA_DEBIAN_VERSION=8u181-b13-1~deb9u1", "CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1", "GOSU_VERSION=1.10 ", "ELASTICSEARCH_VERSION=5.6.12." "ELASTICSEARCH_DEB_VERSION=5.6.12. "" Copy the code
-
Install the Vim editor
apt-get update apt-get install vim Copy the code
-
Go to ElasticSearch and change the version of the elasticSearch plug-in
# Edit file vim plugin-descriptor.properties The modified version corresponds to it elasticsearch.version=5.6.12 Copy the code
-
Restart the container
-
-
Or you can download the version of ElasticSearch by checking the Chinese word segmentation plugin you downloaded
5. Install the client visualization tool
-
Install mobz/ ElasticSearch-head using Docker
docker pull mobz/elasticsearch-head:5 Copy the code
-
2. Start the container
docker run -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5 Copy the code
-
Elasticsearch will automatically connect to your browser
http://localhost:9100/ Copy the code
-
4, create index
6, create index exception processing
-
1. When you click create index and nothing happens, open your browser console and check
-
2, Go to the mobz/ ElasticSearch-head container and modify the code
docker Exec-it Container ID /bin/bash Copy the code
-
3. Modify the /usr/src/app/_site/vendor.js file
# Update package apt-get update # install vim apt-get install vim Copy the code
-
4, modify code 1 (look at line number)
# code contentType: "application/x-www-form-urlencoded # modified to contentType: "application/json; charset=UTF-8" Copy the code
-
5, modify the code and (look at the line number)
# code var inspectData = s.contentType === "application/x-www-form-urlencoded" && # modified to var inspectData = s.contentType === "application/json; charset=UTF-8" && Copy the code
-
6. Restart the container
docker Restart the container ID Copy the code