Introduction to Elastic Search Cluster

I. Download and Installation

Elastic search dependency Java Before installing ES, we must first match java, which is the default that our computer has been completed. Elastic search requires a minimum version of jdk of 1.7.  
First, we download the installation package from the elastic search website. Linux System, download tar package is more convenient. Current version 2.3.3, download address: Elasticsearch 2.3.3 Download
Unzip the tar file after downloading:

tar -zxvf elasticsearch-2.3.3.tar.gz 
  • 1
  • 1

Running Elastic Search

Start the Elastic Search command:

./elasticsearch-2.3.3/bin/elasticsearch
  • 1
  • 1

If everything goes well, you will receive information similar to the following:

[2016-06-18 15:07:50,106][INFO ][node                     ] [Maynard Tiboldt] version[2.3.3], pid[7390], build[218bdf1/2016-05-17T15:40:04Z]
[2016-06-18 15:07:50,106][INFO ][node                     ] [Maynard Tiboldt] initializing ...
[2016-06-18 15:07:50,590][INFO ][plugins                  ] [Maynard Tiboldt] modules [reindex, lang-expression, lang-groovy], plugins [], sites []
[2016-06-18 15:07:50,609][INFO ][env                      ] [Maynard Tiboldt] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [85.6gb], net total_space [111.8gb], spins? [unknown], types [hfs]
[2016-06-18 15:07:50,609][INFO ][env                      ] [Maynard Tiboldt] heap size [990.7mb], compressed ordinary object pointers [true]
[2016-06-18 15:07:50,610][WARN ][env                      ] [Maynard Tiboldt] max file descriptors [10240] for elasticsearch process likely too low, consider increasing to at least [65536]
[2016-06-18 15:07:52,323][INFO ][node                     ] [Maynard Tiboldt] initialized
[2016-06-18 15:07:52,323][INFO ][node                     ] [Maynard Tiboldt] starting ...
[2016-06-18 15:07:52,401][INFO ][transport                ] [Maynard Tiboldt] publish_address {127.0.0.1:9300}, bound_addresses {[fe80::1]:9300}, {[::1]:9300}, {127.0.0.1:9300}
[2016-06-18 15:07:52,406][INFO ][discovery                ] [Maynard Tiboldt] elasticsearch/OawW12ZERyO3CuQrt7SmFQ
[2016-06-18 15:07:55,445][INFO ][cluster.service          ] [Maynard Tiboldt] new_master {Maynard Tiboldt}{OawW12ZERyO3CuQrt7SmFQ}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2016-06-18 15:07:55,456][INFO ][http                     ] [Maynard Tiboldt] publish_address {127.0.0.1:9200}, bound_addresses {[fe80::1]:9200}, {[::1]:9200}, {127.0.0.1:9200}
[2016-06-18 15:07:55,457][INFO ][node                     ] [Maynard Tiboldt] started
[2016-06-18 15:07:55,476][INFO ][gateway                  ] [Maynard Tiboldt] recovered [0] indices into cluster_state
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

This runs a node. (You can open several more terminals, and all the nodes with the same cluster name are in one cluster.)
Notice the line marked with http, which provides information about HTTP addresses (127.0.0.1) and ports (9200), through which we can access our nodes. By default, Elasticsearch uses 9200 to provide access to its REST API.  
Visit http://127.0.0.1:9200/ The browser will output the following information:

{
  "name" : "Obliterator",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.3",
    "build_hash" : "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
    "build_timestamp" : "2016-05-17T15:40:04Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

If you want to access es via server ip, open elastic search-2.3.3/config/elastic search.yml and find the Network section:

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

Remove the comment before network.host: 192.168.0.1 and change it to network.host: 0.0.0.0 
The http part of the information returned above restart es will also become the real local address, which can be accessed through the native real ip:9200.

Close Elastic Search

There are three ways to shut down ES when the ES node needs to be restarted or shut down properly:

  1. In the console, use the CTRL+C key combination.
  2. Terminate server processes by sending TERM signals.
  3. Use REST API curl-XPOST'http://localhost:9200/_shutdown'.

IV. Plug-in Installation

4.1 Install the head plug-in

Installation command:

./elasticsearch-2.3.3/bin/plugin install mobz/elasticsearch-head
  • 1
  • 1

After installation, enter the address in the browser: http://localhost:9200/_plugin/head/ head plug-in can be called to view cluster status, node information, query and so on.

4.2 Installation of IK Segmenter

(a). First use Git clone command to download IK word splitter source code

git clone https://github.com/medcl/elasticsearch-analysis-ik.git
  • 1
  • 1

You can also access github addresses directly( https://github.com/medcl/elasticsearch-analysis-ik ) Click on the Clone or download button on the right and Download ZIP directly.

(b) Unzip the downloaded elastic search-analysis-ik-master.zip.

unzip elasticsearch-analysis-ik-master.zip
  • 1
  • 1

(c.) Packing with maven
Make sure the system has maven installed. Use the mvn-version command to see if Maven has been installed. If not, you can choose the installation method according to the system, such as the mac OS system can use brew. The install maven command completes the installation.
Enter the download directory of the ik segmenter and run the command:

mvn package
  • 1
  • 1

When the package is finished, you can see an additional target folder in the root directory.
(d.) Configure Ik plug-ins
Create a new folder named IK in the elastic search-2.3.3/plugins/directory. Add elastic search-analysis-ik-master/target/releases
/ Elastic search-analysis-ik-1.9.3.zip decompresses and copies all the extracted files to the elastic search-2.3.3/plugins/ik/directory.
Restart es. If configured correctly, there will be no exception information output.  
(e.)ik participle test 
1. First, create an index for testing:

curl -XPUT localhost:9200/index
  • 1
  • 1

2. Create mapping for index:

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
    "fulltext": {
             "_all": {
            "analyzer": "ik"
        },
        "properties": {
            "content": {
                "type" : "string",
                "boost" : 8.0,
                "term_vector" : "with_positions_offsets",
                "analyzer" : "ik",
                "include_in_all" : true
            }
        }
    }
}'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

3. test:

curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"China has13Billion population"
}'
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

The results are as follows:

{
  "tokens" : [ {
    "token" : "China",
    "start_offset" : 0,
    "end_offset" : 2,
    "type" : "CN_WORD",
    "position" : 0
  }, {
    "token" : "State-owned",
    "start_offset" : 1,
    "end_offset" : 3,
    "type" : "CN_WORD",
    "position" : 1
  }, {
    "token" : "13",
    "start_offset" : 3,
    "end_offset" : 5,
    "type" : "ARABIC",
    "position" : 2
  }, {
    "token" : "Billion",
    "start_offset" : 5,
    "end_offset" : 6,
    "type" : "CN_WORD",
    "position" : 3
  }, {
    "token" : "population",
    "start_offset" : 6,
    "end_offset" : 8,
    "type" : "CN_WORD",
    "position" : 4
  } ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

CRUD of Documents

5.1 Index, Type, Document, Field

  • Index is the place where Elastic Search stores data, which can be understood as a database in a relational database.
  • Types are used to distinguish different data types under the same index, which is equivalent to tables in relational databases.
  • Documents are entities stored in Elastic Search and are analogous to relational databases. Each document corresponds to a row of data in a database table.
  • Documents consist of fields, which are equivalent to the attributes of columns in relational databases. The difference is that different documents of ES can have different sets of fields.  
    Contrast relational databases:
Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices   -> Types  -> Documents -> Fields
  • 1
  • 2
  • 1
  • 2

5.2 Create Documents

Take blog content management as an example. The index name is blog and the type is article. Add a new document:

curl -XPUT http://localhost:9200/blog/article/1 -d '
{
      "id": "1",
      "title": "New version of Elasticsearch released!",
      "content": "Version 1.0 released today!",
      "priority": 10,
      "tags": ["announce", "elasticsearch", "release"]
}'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

5.3 Retrieval of Documents

http://localhost:9200/blog/article/1?pretty
  • 1
  • 1

5.4 Update Documents

curl -XPOST http://localhost:9200/blog/article/1/_update -d '{
  "script": "ctx._source.content = \"new content\""
}'
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

5.5 Delete Documents

curl -XDELETE http://localhost:9200/blog/article/1 
  • 1
  • 1

VI. Relevant Concepts

6.1 Nodes and Clusters

Elastic Search is a distributed full-text search engine, which can work as an independent search server or run simultaneously with multiple servers, thus constituting a cluster. Each server in the cluster is called a node.

6.2 slices

When the amount of data is large, it is limited by the capacity of RAM and hard disk, and the computing power of a node is limited. Data can be divided into shards, each of which is a separate lucene index. Each fragment can be stored on different nodes of the cluster. When an index composed of multiple fragments needs to be queried, Elastic Search sends the query to each relevant fragment, and then merges the query results. The process is transparent to the application without knowing the existence of fragmentation.

6.3 copies

A copy is an exact copy of the original slice, which becomes the main slice. All operations on the index directly work on the main slice, each of which can have zero or more sub-slices. If the main partition is lost, the cluster can upgrade a new partition with the sub-partition as the main one.


Reprint address: http://blog.csdn.net/napoay/article/details/51705902

Tags: ElasticSearch curl network Maven

Posted on Tue, 26 Mar 2019 19:03:28 -0700 by Ivan_