Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands commonly used in Elasticsearch development

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you what are the common commands in Elasticsearch development. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

0. Background

Elasticsearch has a rich set of easy-to-understand REST API that can be accessed through HTTP calls in the following ways.

CurlPostmanhead plug-in cerebro tool kibana

In the development practice, I recommend using kibana Dev-tools.

The reasons are as follows:

Prompt function is convenient and fast, efficient and not error-prone 1, Elasticsearch REST URL disassembly 1.1 REST URL and an overview of options

Take a chestnut:

POST products/_search?size=0

{

"aggs": {

"product_aggs": {

"terms": {

"field": "name.keyword"

}

}

}

}

It's easy to call REST API, which consists of four parts in addition to the actual hostname / IP and port:

Verb-the GET,PUT,POST and DELETE parts of the REST call.

In Kibana, you can specify these names directly, and for cURL, use the-X option.

Corresponding to POST in the example

Path-- API and path.

For example, the first part of the / _ cluster / health or / logstash-cron-2020.07.03/_mapping- path is usually the index name, unless it starts with _.

Corresponding to: products/_search in the example, where products is the index.

Parameters-the various options that follow?

Like what? H or? V

Corresponds to:? size=0 in the example. Parameter setting part.

Body-some calls require a JSON body (such as setting options) and will be included in {}

Corresponding to the example: retrieve the statement section.

1.2 Common options

There are some common options for many (but not all) URL. These are:

? help-- help options.

The fields available for API are provided in the list, including short and long names, descriptions, and so on.

For example:

GET _ cat/indices?help

H =-"h"-use the short or long names in the help display above to specify the fields to include in the results. These are separated by commas with no spaces.

For example:

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

In this way, the return result is confused, which is equivalent to the fact that Excel has N column fields, but it is painful to have no header.

The field name is included at the top of the reply. GET _ cat/indices?h=docs.count,store.size&v

The beauty of the-v parameter is mainly reflected in the addition of the header, intuitive interactive presentation.

? SMB'is used for sorting, using the listed fields as the sort key.

As follows: we may see a list of nodes. Including: returns the field name, which is to be displayed and sorted by name name:

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

In addition, Kibana saves your Dev Tools query in cookie.

With the above background, the following list of common development-related commands looks relatively easy.

2. Status & Statistics related command list

The most useful API calls are usually related to the health, status, and statistics of the cluster, such as:

2.1 get information such as version and cluster name. GET /

2.2 obtain cluster health status and other information, including cluster name, number of nodes, number of data nodes, shards and other statistical information. GET / _ cluster/health

2.3 get node list information. Shows heap memory, disk usage, CPU, load, and host roles.

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 healthy GET / _ cluster/health?level=indices&pretty

2.5 Shard Level fragment level healthy GET / _ cluster/health?level=shards&pretty

2.6 get a more in-depth overview of cluster statistics for indexes, documents, caches, segments, 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 & statistical command listing 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 hotspot threads to find out who is occupying GET / _ nodes/hot_threads/, such as CPU resources

3.3 get the index mode quickly.

For example: the method for the total number of documents indexed with all these logstash * prefixes.

GET / _ cat/count/logstash*?v

4. Index-related status & Statistics command listing 4.1 wildcard index list acquisition

Contains: size, document count, status, etc.

GET / _ cat/indices/logstash*?v

4.2 find size's largest index GET / _ cat/indices/logstash-*?v&h=index,ss&s=ss:desc

4.3 get the index GET / _ cat/indices?v&health=yellow with a yellow status

Red red: at least one primary shard is not available. Yellow yellow: at least one copy shard is not available. Green green: both cluster master and replica shards are available, and the cluster is healthy. 5. Set up the relevant list

There are many settings in Elasticsearch, but the most common are the "cluster" and "index" levels.

5.1 Cluster Settings

The most basic view of cluster settings-displays non-default persistence and transient settings information.

GET / _ cluster/settings

Larger list view-includes all default values and uses a plan view to make it easier to read.

GET / _ cluster/settings?include_defaults=true&flat_settings=true

5.2 Index Settings

Gets the list of settings for the specified index.

GET / logstash-cron-2020.08.03/_settings

Gets the meta-information, setting information, and Mapping information of the index.

GET / logstash-cron-2020.08.03

6. Close & delete index 6.1 close index

Support for single or fuzzy matching of multiple indexes.

POST / logstash-*-2020.03.*/_close

6.2 Delete the index

Support for single or fuzzy matching of multiple

DELETE / logstash-*-2020.04.*

7. Troubleshooting list

The operation and maintenance list has been stated before, and the development also needs it.

7.1 get: allocated and unassigned shards. GET / _ cat/shards?v&h=n,index,shard,prirep,state,sto,sc,unassigned.reason,unassigned.details&s=sto,index

7.2View unallocated shards and 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 unassigned details of the specified shard 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 listing 8.1 enumerates all defined templates GET / _ cat/templates?v&s=order,name

8.2 enumerate the template information GET / _ template/logstash with the specified name

9. Snapshot & restore 9.1 lists the snapshot repositories configured in the system. Most other API calls require these names. GET / _ snapshot

9.2 get the status and statistics of any running snapshots GET / _ snapshot/_status

9.3 useful information for taking snapshots GET / _ cat/snapshots/my_repository?v&h=id,status,start_time,duration,indicies,successful_shards,failed_shards,total_shards

10. Sharding allocation and recovery listing 10.1 multipart allocation View GET / _ cat/allocation?v

10.2 multipart recovery to view GET / _ cat/recovery?v

10.3 run the task to view GET / _ cat/pending_tasks?v

10.4 Clean the cache POST / _ cache/clear

Thank you for reading! This is the end of this article on "what are the common commands in Elasticsearch development?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report