Top 10 Concepts of ElasticSearch

1. The Cluster (Cluster)

One or more servers installed with ES nodes are grouped together, which is called a cluster. These nodes hold data and provide search services together. A cluster has a name that uniquely identifies the cluster. This name is called the cluster name. The default cluster name is ElasticSearch. You can configure the cluster name in the config/ elasticSearch.yml file:

cluster.name: es_001
Copy the code

In a cluster, nodes can be in three states: green, yellow, and red:

  • Green: The node is in the healthy state. All primary and secondary shards work properly.
  • Yellow: indicates that the node is in the warning state. All master shards are currently running, but at least one replica shard is not working properly
  • Red: The cluster cannot work properly

2. The Node (the Node)

A server in a cluster is a node that stores data and participates in the indexing and search functions of the cluster. To add a node to a cluster, you only need to set the cluster name. By default, if we start multiple nodes, they can discover each other and automatically form a cluster, but this approach is not reliable and can lead to brain splitting. Therefore, you need to manually configure the cluster information in actual production

cluster.name: esxince
node.name: esxince_node1
discovery.seed_hosts: ["10.25.68.52:3901"."10.25.68.52:3902"."10.25.68.52:3903"]
Copy the code

3. The Index (Index)

  • noun

A collection of documents with similar characteristics

  • The verb

Index data and perform index operations on data

4. Type (Type)

A type is a logical category or partition on an index. Prior to ES6, you could have multiple types in an index. Starting with ES7, you could only have one type in an index

5. Document (the Document)

A unit of data that can be indexed. It’s all in JSON format

6. Shard (Shards)

Indexes are stored on nodes. However, due to the space size and data processing capacity of nodes, the processing effect of a single node may not be ideal. In this case, we can fragment indexes. When creating an index, we need to specify the number of shards. Each shard is itself a fully functional and independent index.

7. Copies (Replicas)

A copy is a copy of the master shard

8. Settings

Index definition information in the cluster, such as the number of index fragments, number of copies, and so on

9. Mapping

Mapping stores information such as the storage type, word segmentation, and whether to store index fields

10. Analyzer

Definition of field word segmentation

ElasticSeasrch vs relational database

Relational database ElasticSearch
The database The index
table type
line The document
column field
Table structure Mapping
SQL DSL
select * from xxx GET http://
update xxx set xx=xx PUT http://
Delete xxx DELETE http://
The index The full text indexing
Root @ ubuntu: / data/es_2901 / plugins/analysis - ik# curl - XPUT http://221.228.85.54:2901/index {"acknowledged":true,"shards_acknowledged":true,"index":"index"}root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# curl -XPOST http://221.228.85.54:2901/index/_mapping - H 'the content-type: application/json - d' {> "properties" : {> "Content" : { > "type": "text", > "analyzer": "ik_max_word", > "search_analyzer": "ik_smart" > } > } > > }' {"acknowledged":true}root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# Root @ ubuntu: / data/es_2901 / plugins/analysis - ik# curl - XPOST http://221.228.85.54:2901/index/_create/1 - H 'Content-Type:application/json' -d'{ "content": "Is the US leaving Iraq a mess? "}' {"_index":"index","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed": 0},"_seq_no":0,"_primary_term":1}root@ubunt root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# Root @ ubuntu: / data/es_2901 / plugins/analysis - ik# curl - XPOST http://221.228.85.54:2901/index/_create/2 - H 'Content-Type:application/json' -d'{ "content": "Young man you rat juice "}' {"_index":"index","_type":"_doc","_id":"2","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed": 0},"_seq_no":1,"_primary_term":1}root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# root@ubuntu:/data/es_2901/plugins/analysis-ik# Root @ ubuntu: / data/es_2901 / plugins/analysis - ik# curl - XPOST http://221.228.85.54:2901/index/_analyze - H 'Content-Type:application/json' -d'{ "analyzer": "Ik_smart ","text":" Is the US leaving China a dog "}' {" tokens ": [{" token" : "the United States", "start_offset" : 0, "end_offset" : 2, "type" : "CN_WORD", "position" : 0}, {" token ":" left ", "start_offset" : 2," End_offset ": 4," type ":" CN_WORD ", "position" : 1}, {" token ":" Chinese ", "start_offset" : 4, "end_offset" : 6, "type" : "CN_WORD", "position" : 2 }, {" token ":" ", "start_offset" : 6, "end_offset" : 7, "type" : "CN_CHAR", "position" : 3}, {" token ":" ", "start_offset" : 7, "end_offset" : 8, "type" : "CN_CHAR", "position" : 4}, {" token ":" a ", "start_offset" : 8, "end_offset" : 9, "type" : "CN_CHAR", "position" : 5}, {" token ":" Dog ", "start_offset end_offset" : 9, "" : 12," type ":" CN_WORD ", "position" : 6}, {" token ":" ", "start_offset" : 12, "end_offset" : 13, "typ e":"CN_CHAR","position":7}]}root@ubuntu:/data/es_2901/plugins/analysis-ik#Copy the code
{"tokens": [{"token":"The United States." "."start_offset":0."end_offset":2."type":"CN_WORD"."position":0}, {"token":"Left"."start_offset":2."end_offset":4."type":"CN_WORD"."position":1}, {"token":"China"."start_offset":4."end_offset":6."type":"CN_WORD"."position":2}, {"token":"The"."start_offset":6."end_offset":7."type":"CN_CHAR"."position":3}, {"token":"Yes"."start_offset":7."end_offset":8."type":"CN_CHAR"."position":4}, {"token":"个"."start_offset":8."end_offset":9."type":"CN_CHAR"."position":5}, {"token":"Dog stuff."."start_offset":9."end_offset":12."type":"CN_WORD"."position":6}, {"token":"吗"."start_offset":12."end_offset":13."type":"CN_CHAR"."position":7}}]Copy the code