Difference between revisions of "Elasticsearch Reference Card"
Jump to navigation
Jump to search
| (10 intermediate revisions by the same user not shown) | |||
| Line 12: | Line 12: | ||
* full settings | * full settings | ||
curl 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty' | curl 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty' | ||
| + | ==Disk filling== | ||
| + | Add or modify the following lines in `elasticsearch.yml` to set the desired disk watermark levels and their corresponding percentages: | ||
| + | |||
| + | <pre> | ||
| + | cluster.routing.allocation.disk.watermark.low: 85% | ||
| + | cluster.routing.allocation.disk.watermark.high: 90% | ||
| + | cluster.routing.allocation.disk.watermark.flood_stage: 95% | ||
| + | </pre> | ||
| + | |||
| + | * low | ||
| + | : Elasticsearch starts allocating new shards to nodes with disk usage below this level. | ||
| + | * high | ||
| + | : Elasticsearch starts throttling shard allocations to nodes with disk usage above this level. | ||
| + | * flood_stage | ||
| + | : Elasticsearch prevents shard allocations on nodes with disk usage above this level. | ||
| + | |||
| + | * check current settings with: | ||
| + | curl -s 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty' | grep watermark | ||
| + | |||
| + | [[Category:Elastic]] | ||
| + | [[Category:ReferenceCards]] | ||
=ADMIN= | =ADMIN= | ||
| Line 50: | Line 71: | ||
curl 'http://localhost:9200/_nodes/stats?pretty' | curl 'http://localhost:9200/_nodes/stats?pretty' | ||
curl 'http://localhost:9200/_nodes/nodeId1,nodeId2/stats?pretty' | curl 'http://localhost:9200/_nodes/nodeId1,nodeId2/stats?pretty' | ||
| + | curl 'http://localhost:9200/_cat/nodes?v=true' | ||
* remove nodes from clusters gracefully | * remove nodes from clusters gracefully | ||
| Line 61: | Line 83: | ||
[[Category:Elastic]] | [[Category:Elastic]] | ||
| + | [[Category:ReferenceCards]] | ||
=INDICES= | =INDICES= | ||
| Line 78: | Line 101: | ||
}' | }' | ||
</pre> | </pre> | ||
| + | |||
| + | * change replica count of an Indice | ||
| + | <pre> | ||
| + | curl -XPUT --header 'Content-Type: application/json' 'http://localhost:9200/_index_name_/_settings' -d '{ | ||
| + | "index" : { | ||
| + | "number_of_replicas" : 1 | ||
| + | } | ||
| + | }' | ||
| + | </pre> | ||
| + | |||
| + | * change replica count of all indices | ||
| + | <pre> | ||
| + | curl -X PUT "127.0.0.1:9200/.*/_settings" -H 'Content-Type: application/json' -d'{ "index" : { "number_of_replicas" : 0 } }' | ||
| + | </pre> | ||
| + | |||
* list all docs in an index | * list all docs in an index | ||
curl -X GET 'http://localhost:9200/elasticsearch_query_examples/_search' | curl -X GET 'http://localhost:9200/elasticsearch_query_examples/_search' | ||
| + | |||
| + | |||
| + | ==Debug Single Node Replica issues== | ||
| + | <pre> | ||
| + | rpm -q opensearch | ||
| + | opensearch-2.19.0-1.x86_64 | ||
| + | |||
| + | |||
| + | curl -s -XGET localhost:9200/_cat/indices | grep yell | ||
| + | yellow open top_queries-2025.02.22-91903 8dXcpNv9QTyciYQCVzKmkQ 1 1 4433 1522 11.8mb 11.8mb | ||
| + | yellow open top_queries-2025.02.23-91904 CFNMBEGBSnieQ5oYsM3Q8g 1 1 7127 1513 16.1mb 16.1mb | ||
| + | |||
| + | |||
| + | curl -s -X GET "localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true" | jq '.defaults."cluster.default_number_of_replicas"' | ||
| + | "1" | ||
| + | |||
| + | vim /etc/opensearch/opensearch.yml | ||
| + | --- | ||
| + | cluster.default_number_of_replicas: 0 | ||
| + | --- | ||
| + | |||
| + | systemctl restart opensearch | ||
| + | |||
| + | |||
| + | curl -s -X GET "localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true" | jq '.defaults."cluster.default_number_of_replicas"' | ||
| + | "0" | ||
| + | |||
| + | curl https://raw.githubusercontent.com/joe-speedboat/linux.scripts/refs/heads/master/shell/opensearch_template_replica_debug.sh | bash | ||
| + | |||
| + | curl -X PUT "127.0.0.1:9200/top_queries-*/_settings" -H 'Content-Type: application/json' -d' | ||
| + | { | ||
| + | "index": { | ||
| + | "number_of_replicas": 0 | ||
| + | } | ||
| + | }' | ||
| + | |||
| + | |||
| + | curl -s -XGET localhost:9200/_cat/indices | grep top_quer | ||
| + | green open top_queries-2025.02.22-91903 8dXcpNv9QTyciYQCVzKmkQ 1 0 4433 1522 11.8mb 11.8mb | ||
| + | green open top_queries-2025.02.23-91904 CFNMBEGBSnieQ5oYsM3Q8g 1 0 7127 1513 16.1mb 16.1mb | ||
| + | </pre> | ||
| + | |||
| + | |||
=SHRADS= | =SHRADS= | ||
| + | * list shrads | ||
| + | curl -XGET localhost:9200/_cat/shards?v | ||
| + | |||
| + | * show details of a shard | ||
| + | curl -X GET 'http://localhost:9200/_cat/shards/graylog_39?v' | ||
| + | |||
* move shards from one node to another | * move shards from one node to another | ||
<pre> | <pre> | ||
| Line 110: | Line 197: | ||
[[Category:Elastic]] | [[Category:Elastic]] | ||
| + | [[Category:ReferenceCards]] | ||
| + | |||
| + | ==Delete Unassigned Shrads== | ||
| + | <pre> | ||
| + | curl http://localhost:9200/_cluster/health?pretty | ||
| + | curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason | ||
| + | curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk {'print $1'} | xargs -i curl -XDELETE "http://localhost:9200/{}" | ||
| + | curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason | ||
| + | curl http://localhost:9200/_cluster/health?pretty | ||
| + | </pre> | ||
| + | |||
| + | [[Category:Elastic]] | ||
| + | [[Category:ReferenceCards]] | ||
Latest revision as of 14:44, 25 February 2025
Contents
1 OVERVIEW
- get version and details
curl -XGET 'http://localhost:9200'
2 CLUSTER
curl 'http://localhost:9200/_cluster/health?pretty' curl 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s&pretty' curl 'http://localhost:9200/_cluster/state?pretty' curl 'http://localhost:9200/_cluster/stats?human&pretty' curl 'http://localhost:9200/_cluster/pending_tasks?pretty'
- full settings
curl 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty'
2.1 Disk filling
Add or modify the following lines in `elasticsearch.yml` to set the desired disk watermark levels and their corresponding percentages:
cluster.routing.allocation.disk.watermark.low: 85% cluster.routing.allocation.disk.watermark.high: 90% cluster.routing.allocation.disk.watermark.flood_stage: 95%
- low
- Elasticsearch starts allocating new shards to nodes with disk usage below this level.
- high
- Elasticsearch starts throttling shard allocations to nodes with disk usage above this level.
- flood_stage
- Elasticsearch prevents shard allocations on nodes with disk usage above this level.
- check current settings with:
curl -s 'http://localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true&pretty' | grep watermark
3 ADMIN
- force a synced flush
curl -XPOST 'localhost:9200/_flush/synced'
- Change the number of shards being recovered simultaneously per node
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"cluster.routing.allocation.exclude._ip" : "1.2.3.4"
}
}';echo
- Change the recovery speed
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"indices.recovery.max_bytes_per_sec" : "80mb"
}
}';echo
- Change the number of concurrent streams for a recovery on a single node
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"indices.recovery.concurrent_streams" : 6
}
}';echo
4 NODE
- get infos
curl 'http://localhost:9200/_nodes?pretty' curl 'http://localhost:9200/_nodes/stats?pretty' curl 'http://localhost:9200/_nodes/nodeId1,nodeId2/stats?pretty' curl 'http://localhost:9200/_cat/nodes?v=true'
- remove nodes from clusters gracefully
curl -XPUT localhost:9200/_cluster/settings -d '{
"transient" :{
"cluster.routing.allocation.exclude._ip" : "1.2.3.4"
}
}';echo
5 INDICES
- list
curl -X GET 'http://localhost:9200/_cat/indices?v'
- delete
curl -X DELETE 'http://localhost:9200/examples'
- back up
curl -XPOST --header 'Content-Type: application/json' http://localhost:9200/_reindex -d '{
"source": {
"index1": "someexamples"
},
"dest": {
"index2": "someexamples_copy"
}
}'
- change replica count of an Indice
curl -XPUT --header 'Content-Type: application/json' 'http://localhost:9200/_index_name_/_settings' -d '{
"index" : {
"number_of_replicas" : 1
}
}'
- change replica count of all indices
curl -X PUT "127.0.0.1:9200/.*/_settings" -H 'Content-Type: application/json' -d'{ "index" : { "number_of_replicas" : 0 } }'
- list all docs in an index
curl -X GET 'http://localhost:9200/elasticsearch_query_examples/_search'
5.1 Debug Single Node Replica issues
rpm -q opensearch
opensearch-2.19.0-1.x86_64
curl -s -XGET localhost:9200/_cat/indices | grep yell
yellow open top_queries-2025.02.22-91903 8dXcpNv9QTyciYQCVzKmkQ 1 1 4433 1522 11.8mb 11.8mb
yellow open top_queries-2025.02.23-91904 CFNMBEGBSnieQ5oYsM3Q8g 1 1 7127 1513 16.1mb 16.1mb
curl -s -X GET "localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true" | jq '.defaults."cluster.default_number_of_replicas"'
"1"
vim /etc/opensearch/opensearch.yml
---
cluster.default_number_of_replicas: 0
---
systemctl restart opensearch
curl -s -X GET "localhost:9200/_cluster/settings?include_defaults=true&flat_settings=true" | jq '.defaults."cluster.default_number_of_replicas"'
"0"
curl https://raw.githubusercontent.com/joe-speedboat/linux.scripts/refs/heads/master/shell/opensearch_template_replica_debug.sh | bash
curl -X PUT "127.0.0.1:9200/top_queries-*/_settings" -H 'Content-Type: application/json' -d'
{
"index": {
"number_of_replicas": 0
}
}'
curl -s -XGET localhost:9200/_cat/indices | grep top_quer
green open top_queries-2025.02.22-91903 8dXcpNv9QTyciYQCVzKmkQ 1 0 4433 1522 11.8mb 11.8mb
green open top_queries-2025.02.23-91904 CFNMBEGBSnieQ5oYsM3Q8g 1 0 7127 1513 16.1mb 16.1mb
6 SHRADS
- list shrads
curl -XGET localhost:9200/_cat/shards?v
- show details of a shard
curl -X GET 'http://localhost:9200/_cat/shards/graylog_39?v'
- move shards from one node to another
curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
"commands" : [
{
"move" :
{
"index" : "indexname", "shard" : 1,
"from_node" : "nodename", "to_node" : "nodename"
}
}
]
}';echo
- force the allocation of an unassigned shard with a reason
curl -XPOST 'http://localhost:9200/_cluster/reroute?explain' -d '{
"commands" : [ {
"allocate" : {
"index" : "indexname", "shard" : 0, "node" : "nodename"
}
} ]
}';echo
6.1 Delete Unassigned Shrads
curl http://localhost:9200/_cluster/health?pretty
curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk {'print $1'} | xargs -i curl -XDELETE "http://localhost:9200/{}"
curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
curl http://localhost:9200/_cluster/health?pretty