[Elasticsearch Notes] (1) Installation and preliminary understanding of concepts and several common methods

1. Installation

Download the compressed package from the official website, unzip it on the windows system and use it, run the .bat file in the /bin folder to run it

(The modules in the modules folder will be automatically loaded, and the configuration used is in the elasticsearch.yml in the config folder, such as what the node.name node name is and the like)

Official website: https://www.elastic.co/cn/elasticsearch/

Enter http://localhost:9200/?pretty in the browser for initial access, and pretty will let Elasticsearch beautify the output (pretty-print) JSON response to make it easier to read.

If the machine does not have a java environment, you can download it from Baidu and now basically need a version above jdk1.8

2. Brief description or translation of some concepts

1. Cluster

There are multiple nodes under a cluster. cluster_name is the cluster name, the default name is elasticsearch, which can be modified

2. Node

The node can set the node name, if not set, it will discover each other, and automatically form and join a cluster named elasticsearch.

3. For data content

(1), Index (Index)

Large range, say index is car

(2), type (Type)

type is a logical data classification in index. For example, the index is based on cars, type is the data of two wheels, and type is the data of four wheels.

type is the data of two wheels. It may only record id and name.

type is the data of the four wheels, and a field of scrapping time may be added on the basis of id and name

The index (index) is equivalent to the database, the type (type) is equivalent to the data table, and the mapping (Mapping) is equivalent to the table structure of the data table.

(3), documents and fields (Document and field)

For example, the index is based on the car, and the type is two documents of the data of the two wheels.

{"number": "2","name": "Shared bicycle"}, {"number": "3","name": "Family bicycle"}

A {} is a document, number and name are called fields

Note that although the document Document physically resides in the index Index , the document must actually be assigned a type in the index.

4, shard (fragmentation)

An index will contain multiple shards for storage, (1) facilitate horizontal expansion (such as adding servers), (2) allow cross-shards (possibly on multiple nodes) to distribute and parallelize operations, thereby improving performance/throughput quantity

Each shard is a lucene index and can process requests independently.

(As of LUCENE-5843, the limit is 2,147,483,519 (= Integer.MAX_value-128) docs. You can monitor the shard size using the _cat/shards API)

For example, the data of tricycles may be placed in one shard, and the data of bicycles in another shard. If there is more data in the future, it will be convenient to expand.

(1) primary shard: The primary shard corresponds to the replica shard, and the copy source of the backup shard of the replica shard is called the primary shard

(2) replica shard: backup shard, which is a copy of primary shard, responsible for fault tolerance, and bears the load of read requests

The advantage of backup fragmentation is

(1) It provides high availability if a shard/node fails. For this reason, it is important to note that the replicated shard is never allocated on the same node as the original/primary shard it was replicated from (meaning cannot be on the same node as the primary shard)

(2) It allows you to scale your search volume/throughput, since searches can be performed in parallel on all replicas

By default, each index of Elasticsearch allocates 5 primary shards and 1 copy (equivalent to 5 shards with a backup),

This means that if there are at least 2 nodes in the cluster (primary shard and replica shard cannot be on the same node),

Then the index will have 5 primary shards and another 5 replica shards (1 full replica), for a total of 10 shards per index.

 

3. Initial interaction with Elasticsearch

1. After running the startup file after installation, the browser can input a normal request that meets the specification to interact.

But it is more difficult for complex requests. You can download a Kibana compressed package from the official website, and after decompression, run the bin\kibana.bat file to use Kibana

Similar to the effect of postman, it is easy to learn, and later learn the interaction between java language and Elasticsearch.

2. Common methods and official api

https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs.html

https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search.html

Partners who feel headaches when they read English can install a plug-in for the browser, right-click to translate the page directly, and the original English will be retained, which is very convenient

Plug-in address: https://saladict.crimx.com/download.html

Common methods:

(1) increase

PUT /index/type/id

{json document content}

(2) Modify (modify by replacing, add a document with a certain id, there is already a document, and it will be automatically overwritten. You need to bring all the fields, otherwise an error will be reported)

PUT  /index/type/id

{json document content}

(3) Modify (you can only change a certain field)

POST /index/type/id/_update

{json document content}

(4) query

GET /index/type/id

{json document content}

(5) delete

DELETE  /index/type/id

(6) Query system health status

GET /_cat/health?v

(7) Several query methods search

  • URI SEARCH

    performs a search request purely using a URI.
    GET /index/type/_search?parameter=

    Example:
    GET twitter/tweet/_search?q=user:kimchy&sort=user:desc
    其它参数在官方文档中有说明
    https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-uri-request.html
    这种搜索方式不常用
    
  • Query DSL ( DSL: Domain Specified Language )

    is a query method with json. The query conditions are all in json, which is very convenient when there are many query conditions. For
    example, query all data:

    GET /index/type/_search
    {"query ": { "match_all": {} }}

    Other content will be added next time
 

 

Guess you like

Origin blog.csdn.net/mudarn/article/details/114363340