编程知识 cdmana.com

List of commonly used commands for dry goods | elasticsearch

0、 background

Elasticsearch Having a rich and easy to understand set of REST API, these API   It can be passed in the following ways HTTP Call to access .

  • Curl

  • Postman

  • head plug-in unit

  • cerebro Tools

  • kibana

Develop actual combat links , I recommend using :kibana Dev-tools.

Here's why :

  • Prompt function

  • Convenient and quick 、 Efficient

  • Not easy to make mistakes

This paper combines years of practical experience and network resources , Sort out the most important command list in the development process , I hope it helps you !

1、Elasticsearch REST URL Take apart

1.1 REST URL And options Overview

Take a chestnut :

POST products/_search?size=0
{
  "aggs": {
    "product_aggs": {
      "terms": {
        "field":"name.keyword"
      }
    }
  }
}

call REST API be prone to , Except for the actual host name / IP And out of port , It also has four parts :

  • Verb ——REST Called GET,PUT,POST and DELETE part .

stay Kibana in , You can specify these names directly , about cURL, Please use -X Options .

Corresponding to... In the example :POST

  • route ——API And the path .

for example :/_cluster / health or /logstash-cron-2020.07.03/_mapping- The first part of the path is usually the index name , Unless it uses _ start .

Corresponding to... In the example :products/_search, among products It's the index .

  • Parameters —— The options that follow ?

for example ?h or ?v

Corresponding to... In the example :?size=0. Parameter setting part .

  • Text —— Some calls require JSON Text ( For example, setting options ), And will be included in {} in

Corresponding to... In the example : Search statement part .

1.2 Common options

There are some general options for many ( Not all )URL. These are :

  • ?help—— Help options .

Will be provided in the list API Available fields , It contains short and long names 、 Explanation, etc .

give an example :

GET _cat/indices?help
  • ?h =-“ h”—— Use the top “ help ” Short or long names in the display specify the fields to include in the results . These are separated by commas , There are no spaces .

give an example :

GET _cat/indices?h=docs.count,store.size

So the result is not clear when we come back later , amount to Excel Yes N Column fields , But it's not the same as the header , A lot of pain !

  • ?v——'v' Include the field name at the top of the reply .

GET _cat/indices?h=docs.count,store.size&v

-v The beauty of parameters is mainly reflected in : With a header , Intuitive interactive presentation .

  • ?s——'s' Used to sort , Use the fields listed as sort keys .

As shown below : We might see a list of nodes . Include : Return field name , The field name should be displayed by name name Sort :

GET /_cat/nodes?v&h=heap.percent,diskUsedPercent,cpu,master,name&s=name

in addition ,Kibana Will take your Dev Tools The query is saved in cookie in .

With the above background knowledge , The following list of common development related commands seems relatively easy .

2、 state & Statistics related command list

The most useful API Calls are usually related to the health of the cluster , Status is related to statistics , for example :

2.1 Get the version and cluster name and so on .

GET / 

2.2 Get cluster health status and other information , Include cluster name 、 Number of nodes 、 Number of data nodes 、 Some statistical information about fragmentation, etc .

GET /_cluster/health

2.3 Get node list information . Shows heap memory 、 Disk usage ,CPU 、 Load and host role .

purpose : Used to monitor load and disk usage as well as host roles .

GET /_cat/nodes?v&h=heap.percent,diskUsedPercent,cpu,load_1m,master,name&s=name

2.4 Index Level Index level health

GET /_cluster/health?level=indices&pretty

2.5 Shard Level Slice level health

GET /_cluster/health?level=shards&pretty

2.6 Get index , file , cache , paragraph , A more in-depth overview of cluster statistics for nodes, etc .

purpose : Helps with basic troubleshooting .

GET /_cluster/stats 

2.7 Get more statistics at the node level , Including heap usage, etc .

GET /_nodes/stats 

3、 Thread related state & List of statistical commands

3.1 Long but useful thread queue view

GET /_cat/thread_pool?v&h=node_name,name,type,active,size,queue,queue_size,rejected,largest,completed,min,max&s=node_name,name

3.2 View hot threads , Used to find out who is occupying CPU Resources, etc

GET /_nodes/hot_threads/ 

3.3 Quick access to index mode .

for example : All of these logstash * Prefix index the total number of documents .

GET /_cat/count/logstash*?v

4、 Index related status & List of statistical commands

4.1 Wildcard index list get

contain : size , Document count , State, etc .

GET /_cat/indices/logstash*?v

4.2 find size The biggest index

GET /_cat/indices/logstash-*?v&h=index,ss&s=ss:desc

4.3 Get index with yellow status

GET /_cat/indices?v&health=yellow
  • Red red: At least one primary tile is not available .

  • yellow yellow: At least one replica fragment is not available .

  • green green: Cluster master 、 All copies are available in Shards , Cluster health .

5、 Set up the relevant list

Elasticsearch There are many settings in , But the most common is “ colony ” and “ Indexes ” Level .

5.1   Cluster settings

The most basic view of cluster settings —— Display non default persistence and transient settings information .

GET /_cluster/settings

Larger list view —— Include all default values , And use a plan view to make it easier to read .

GET /_cluster/settings?include_defaults=true&flat_settings=true

5.2 The index set

Get the setting list information of the specified index .

GET /logstash-cron-2020.08.03/_settings 

Get the meta information of the index 、 Set up information and Mapping Information .

GET /logstash-cron-2020.08.03 

6、 close & Delete index

6.1 Close index

Supports single or fuzzy matching of multiple indexes .

POST /logstash-*-2020.03.*/_close 

6.2 Delete index

Support single or fuzzy matching multiple

DELETE /logstash-*-2020.04.* 

7、 Troubleshooting checklist

It was stated in the operation and maintenance list before , Development also requires .

7.1 obtain : Allocated and unallocated tiles .

GET /_cat/shards?v&h=n,index,shard,prirep,state,sto,sc,unassigned.reason,unassigned.details&s=sto,index

7.2 View the unallocated shards and their reasons

GET _cat/shards?v&h=index,shard,prirep,state,unassigned.reason&s=state 

7.3 View unassigned details

GET /_cluster/allocation/explain

7.4 View the details of the specified partition unassigned

GET /_cluster/alloGET /_cluster/allocation/explain 
{ "index": "logstash-cloudtrail-2019.10.16", "shard": 0, "primary": true} cation/explain { "index": "logstash-cloudtrail-2019.10.16", "shard": 0, "primary": true} 

7.5 Offline node

PUT _cluster/settings?pretty
{
  "transient": {
    "cluster.routing.allocation.exclude._ip": "10.0.0.1"
  }
}

8、 Template list

8.1 List all templates defined

GET /_cat/templates?v&s=order,name

8.2 Lists the template information for the specified name

GET /_template/logstash

9、 snapshot & recovery

9.1 List the snapshot repositories configured in the system . Most of the others API Calls need these names .

GET /_snapshot 

9.2 Get the status and statistics of any running snapshot

GET /_snapshot/_status 

9.3 Get useful information about the snapshot

GET /_cat/snapshots/my_repository?v&h=id,status,start_time,duration,indicies,successful_shards,failed_shards,total_shards

10、 Partition allocation and recovery list

10.1 Slice distribution view

GET /_cat/allocation?v

10.2 Slice back to view

GET /_cat/recovery?v

10.3 Run task view

GET /_cat/pending_tasks?v

10.4 Clean cache

POST /_cache/clear

Summary

The list is not exhaustive , The purpose of the checklist is just to sort out the knowledge system .

And the acquisition of basic knowledge is still recommended through Official documents You can see it. , Premise : Be familiar with the directory structure of official documents , To be able to check 、 Check it out , Gradually master and develop practical knowledge .

Reference resources :

https://www.elkman.io/blog/useful-elasticsearch-api-urls

https://preview.mailerlite.com/u3c7e3/1490690490360665893/f2l9/


recommend :

dried food | Elasticsearch List of commonly used operation and maintenance commands

blockbuster | screwing Elasticsearch Methodological cognitive checklist (2020 It was updated on May 1 )

more short time more Learn quickly more More dry !

China 40%+Elastic Certified engineers come from !

版权声明
本文为[Mingyi world]所创,转载请带上原文链接,感谢

Scroll to Top