Getting Started with elasticsearch clusters

Source: Internet
Author: User
Tags curl documentation zip git clone
First, download and install

Elasticsearch relies on Java, the first to install ES before installing the Java, which is the default of our computer has been completed. Elasticsearch requires a minimum JDK version of 1.7.
First download the installation package from Elasticsearch official website, we are Linux system, download the TAR package is more convenient. The current version is 2.3.3, download address: Elasticsearch 2.3.3 Download
Unzip the tar file when the download is complete:

Second, running Elasticsearch

To start the Elasticsearch command:

./elasticsearch-2.3.3/bin/elasticsearch

If all 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][e NV] [Maynard Tiboldt] using [1] data paths, mounts [[[/(/dev/disk1]]], net usable_space [85.6GB], NE T 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] M Ax 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,47 6][info][gateway] [Maynard Tiboldt] recovered [0] indices into Cluster_statE
 

This will run up a node. (You can open several terminals, and the nodes with the same cluster name are in a cluster).
Notice the line with the HTTP tag, which provides information about the HTTP address (127.0.0.1) and the port (9200), and we can access our nodes through this address and port. By default, Elasticsearch uses 9200来 to provide access to its REST API.
To access 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 "
}

If you want to access ES via server IP, open elasticsearch-2.3.3/config/elasticsearch.yml and locate 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:
# 

Remove the annotations before network.host:192.168.0.1 and modify them to network.host:0.0.0.0
Restarting ES the HTTP portion of the information returned above will also become the real native address, which can be accessed through the native real ip:9200 access es. third, close the Elasticsearch

There are three ways to turn off ES when you need to restart the ES node or shut down normally: in the console, use CTRL + C key combination. Terminates the server process by sending a term signal. Use rest apicurl-xpost ' Http://localhost:9200/_shutdown '. four, plug-in installation 4.1 Installing the head plug-in

installation command:

./elasticsearch-2.3.3/bin/plugin Install Mobz/elasticsearch-head

After installation, enter the address in the browser: http://localhost:9200/_plugin/head/can call the head plugin to see the status of the cluster, node information, do queries, and so on. 4.2 Installing the IK word breaker

(a). First download the IK word breaker source using the git clone command

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

You can also directly access the GitHub address (Https://github.com/medcl/elasticsearch-analysis-ik) by clicking on the right clone or download button and then download zip to download directly.

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

Unzip Elasticsearch-analysis-ik-master.zip

(c.) Using MAVEN to package
Make sure MAVEN is installed and use the Mvn-version command to see if MAVEN is already installed. If not installed, you can choose the installation method according to the system, such as Mac OS System can use the Brew install MAVEN command to complete the installation.
Go to the download directory of the IK word breaker and run the command:

MVN Package

After the package is complete, you can see a target folder in the root directory.
(d.) Configuring the IK plug-in
Create a new folder named IK under the elasticsearch-2.3.3/plugins/directory. Put elasticsearch-analysis-ik-master/target/releases
/elasticsearch-analysis-ik-1.9.3.zip unzip and copy all the extracted files to the elasticsearch-2.3.3/plugins/ik/directory.
Restart ES, if configured correctly, there will be no exception information output.
(E.) IK word breaker test
1. First create an index for testing:

Curl-xput Localhost:9200/index

2. Create a mapping for index indexes:

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
            }}}
'

3. Test:

Curl ' http://localhost:9200/index/_analyze?analyzer=ik&pretty=true '-d '
{
"text": "China has 1.3 billion population"
} '

The results appear as follows:

{"
  tokens": [{
    "token": "China",
    "Start_offset": 0,
    "End_offset": 2, "
    type": "Cn_word",
    "posit Ion ": 0
  }, {
    " token ":" State ",
    " Start_offset ": 1,
    " End_offset ": 3,
    " type ":" Cn_word ",
    " pos Ition ": 1
  }, {
    " token ":" + ",
    " Start_offset ": 3,
    " End_offset ": 5,
    " type ":" ARABIC ",
    " p Osition ": 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
  }]
}
v. Documentation CRUD 5.1 indexes, types, documents, fieldsAn index is where Elasticsearch stores data, which can be understood as a database in a relational database. Types are used to differentiate between different data types under the same index, which is equivalent to a table document in a relational database that is stored in elasticsearch, an analogy to a relational database, and each document is equivalent to a row of data in a database table. A document consists of fields that correspond to the properties of a column in a relational database, and different documents of ES can have different field collections.
Compare relational databases:
Elasticsearch Indices, Columns Types, Tables, Databases, relational DB  Gt Documents, Fields
5.2 Creating a document

Take the blog content management as an example, the index name is the blog, the type is article, and a new document is added:

Curl-xput http://localhost:9200/blog/article/1-d '
{
      "id": "1",
      "title": "New version of Elasticsearch released! ",
      " content ":" Version 1.0 released today! ",
      " priority ": Ten,
      " tags ": [" Announce "," Elasticsearch "," release "]
} '
5.3 Retrieving documents
Http://localhost:9200/blog/article/1?pretty
5.4 Updating Documents
Curl-xpost http://localhost:9200/blog/article/1/_update-d ' {
  "script": "ctx._source.content = \" New content\ ""
}'
5.5 Deleting a document
Vi. Related Concepts 6.1 Nodes and clusters

Elasticsearch is a distributed full-text search engine that can either work as a standalone search server or run concurrently with multiple servers, which makes up a cluster (cluster), where each server in the cluster is called a node ( node). 6.2 Shards

When the amount of data is large, it is limited by the capacity of RAM and hard disk, while the computing power of a node is finite. You can slice the data, each part is a separate Lucene index, and become a shard (shard). Each shard can be stored on different nodes in the cluster. When you need to query an index that consists of multiple shards, Elasticsearch sends the query to each related shard, and then merges the query results. The process is transparent to the application without knowing the existence of the Shard. 6.3 Copy

A copy is an exact copy of the original Shard, and the original Shard becomes the primary shard. All operations on the index are directly on the primary shard, and each primary shard can have 0 or more secondary shards. The primary shard is lost, and the cluster can promote a secondary shard to the primary new Shard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.