preface

Make writing a habit together! This is the 12th day of my participation in the “Gold Digging Day New Plan · April More text Challenge”. Click here for more details.

🍊 author introduction: refused to cross the river east, a programmer from the second-tier city, committed to using “obscene” method to solve tedious problems, so that complex problems become easy to understand. 🍊 Supported by: like 👍, follow 💖, leave a message 💌~

Elasticsearch is available for Windows 10, Windows 10, Windows 10, Windows 10, Windows 10, and Windows 10. To help you get started quickly. Let’s cut to the chase.

🍊 p.s. If you haven’t set up their own Elasticsearch, can teach you a Java reference great wisdom | build Elasticsearch Win10 environment

Elasticsearch quick start

🍓🍓Elasticsearch core concept 🍓🍓

There are a few core Elasticsearch concepts that we need to know, and understanding them will help us a lot 👇

🍎The Index Index🍎

An index is a collection of documents that have similar characteristics (for example, you can have an index of student information, an index of course information). An index is identified by a name (which must be lowercase) that is used when indexing, searching, updating, and deleting documents corresponding to the index. Indexing, as a verb, means indexing data and the operation of indexing data.

After you start Elasticsearch, you can go to http://localhost:9200/_cat/indices directly in your browser. V (the argument v is used to request that the table header be returned in the result) to see all indexes. If health status index uuid pri rep docs. Count docs. Deleted store.size pri.store.size is displayed, no index has been created. Then we can create our first index via Kibana (visit http://127.0.0.1:5601/), as shown below 👇

PUT /test? Pretty indicates that we need to create an index named test. The pretty parameter requires that it return a beautiful JSON resultWe can also view the index information via Kibana 👇

🍎Nodes and Clusters 🍎

A node is a running instance of Elasticsearch, which you can think of as a single server. A cluster is a collection of one or more nodes that work together, share data, and provide failover and scaling capabilities. A cluster has a unique name (default: “ElasticSearch”), and a node can only be added to a cluster by specifying its name.

We can access http://localhost:9200/_cat/health in the browser? V to view the current cluster status

The cluster status has three values:

  • Green: At its best
  • Yellow: Data and the cluster are available, but the backup of the cluster is bad
  • Red: Data and cluster are unavailable

In the meantime, we can visit http://localhost:9200/_cat/nodes? V to view node information 👇

🍎TYPE (TYPE) 🍎

In an index, you can define one or more types. A type corresponds to a logical classification of your index, the semantics of which are entirely up to you. Typically, a type is defined for documents that have a common set of fields. For example, if you run a shopping platform and you store all your data in an index, you can define one type for user data, another type for merchandise data, and another type for order data. This is a bit like building a table in Mysql, putting the same type of data in the same table.

🍎Document 🍎

Is a document a basic unit of information that can be indexed (the document is represented in JSON format), or in the case of the shopping platform above, you can have a document for a particular customer, or a document for a particular product. You can store any number of documents in a single index or type. This is a bit like how a table in Mysql can have several pieces of data.

🍎Field 🍎

It is equivalent to several fields owned by a table in Mysql, which can classify and identify document data according to different attributes.

🍎Near real time (NRT) 🍎

Elasticsearch is a near real-time search engine. This means that there is a slight delay (typically 1 second) from indexing a document until it can be searched.

🍎 Shards and Replicas 🍎

An index can store a large amount of data beyond the hardware limit of a single node. For example, an index with 1 billion documents takes up 1TB of disk space, yet no single node has that much disk space, or a single node is too slow to process search requests for our needs. To solve this problem, Elasticsearch provides the ability to divide an index into several pieces, called sharding. When you create an index, you specify the number of shards you want, and each shard is itself a fully functional and independent “index” that can be placed on any node in the cluster. In an operating environment where failure can occur at any time, such as when a shard or node is offline for some reason or disappears for some reason, a failover mechanism is needed. Elasticsearch also solves this problem by allowing us to create one or more copies of a shard. These copies are called copied shards (i.e. copies). Once we have copied the shard, each index has a primary shard (source shard) and a replicated shard (copied shard).

Sharding and replication are very important, sharding allows us to split or expand content capacity horizontally, replication improves availability, and most importantly both sharding and replication help us improve performance and throughput.

🍎 Mapping 🍎

Mapping is a set of restrictions on how data can be processed and rules, such as the data type of a field, default value, whether it is indexed, etc. These are all restrictions in mapping. Elasticsearch allows you to create a map for Elasticsearch data. This allows you to create a map for Elasticsearch data.

🍓🍓Elasticsearch basic operation 🍓🍓

How to create and query an index using Kibana 👇

🍌Remove the index🍌

DELETE /test? Pretty (test is the name of the index, and the pretty argument requires it to return a nice JSON result)

🍌Add documents and build indexes🍌

//index indicates the name of the index, type indicates the type of the index, and ID indicates the ID of the data
PUT /index/type/id
{
  "The json data"
}
Copy the code

Let’s take a concrete example 👇

PUT /test/user/19960911
{
  "id": 19960911."userId": "00001"."userName": "liziye"
}
Copy the code

We can add a document successfully by executing the above statement in Kibana

🍌Querying a specified document🍌

GET /test/user/19960911 (query the document we just added)

🍌Modify a document (all changes) 🍌

// All changes are to replace the document directly. All fields must be added before the document can be modified
PUT /test/user/19960911
{
  "id": 19960911."userId": "00002"."userName": "liziye"
}

Copy the code

🍌Modifying a document (partial modification) 🍌

POST /test/user/19960911/_update
{
    "doc": {"userId":"00003"}}Copy the code

🍌Query all documents 🍌

GET /test/user/_search

The returned result contains several attributes, which are briefly explained here:

  • Took: Milliseconds
  • Timed_out: indicates whether timeout occurs
  • _ Shards: Data is split into 5 shards
  • Hits. Total: indicates the number of query results
  • Hits. max_score: Hits. max_score: hits.max_score: hits.max_score: hits.max_score: Hits. max_score: Hits. max_score: Hits. max_score: Hits. max_score
  • Hits. hits: details of documents that match the search

🍌Paging query all documents🍌

GET /test/user/_search
{
  "query": { "match_all": {}},"from": 1."size": 3
}
Copy the code

🍌Delete the document 🍌

DELETE /test/user/19960911

summary

As a beginner of Elasticsearch, I have very limited experience, so if you have any questions about Elasticsearch, please feel free to leave them in the comments and we will discuss them later 🙇

Please take a thumbs up and a follow (✿◡‿◡) for this article ~ a crab (●’◡’●)

If there are mistakes in the article, welcome to comment correction; If you have a better, more unique understanding, you are welcome to leave your valuable ideas in the comments area.

Love what you love, do what you do, listen to your heart and ask nothing