-
Purge unassigned shards
curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk {'print $1'} | xargs -i curl -XDELETE "http://localhost:9200/{}"
-
Increase numbers of shards https://www.elastic.co/guide/en/elasticsearch/reference/7.17/size-your-shards.html
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.allocation.total_shards_per_node" : 100000
}
}
- Query nested key for value
# query.json
{
"query": {
"match": {
"source.agent.name": "xxxx-xxxx-xxxx"
}
}
}
curl -XGET "http://your_elasticsearch_host:9200/_search" -H 'Content-Type: application/json' -d @query.json
- Reindex data to reduces number of shards
POST _reindex
{
"source": {
"index": "my-index-2099.10.*"
},
"dest": {
"index": "my-index-2099.10"
}
}
- Clean reindex
# First of all: enable blocks write to enable clonage
PUT /my_index/_settings
{
"settings": {
"index.blocks.write": true
}
}
# clone index into a temporary index
POST /my_index/_clone/my_index-000001
# Copy back all documents in the original index to force their reindexetion
POST /_reindex
{
"source": {
"index": "my_index-000001"
},
"dest": {
"index": "my_index"
}
}
# Disable blocks write
PUT /my_index/_settings
{
"settings": {
"index.blocks.write": false
}
}
# Finaly delete the temporary index
DELETE my_index-000001
```# First of all: enable blocks write to enable clonage
PUT /my_index/_settings
{
"settings": {
"index.blocks.write": true
}
}
# clone index into a temporary index
POST /my_index/_clone/my_index-000001
# Copy back all documents in the original index to force their reindexetion
POST /_reindex
{
"source": {
"index": "my_index-000001"
},
"dest": {
"index": "my_index"
}
}
# Disable blocks write
PUT /my_index/_settings
{
"settings": {
"index.blocks.write": false
}
}
# Finaly delete the temporary index
DELETE my_index-000001
-
Get stats of index
curl -X GET 'http://127.0.0.1:9200/system-2023-01/_stats' | jq .
-
Help avoiding errors with a simple copy-your-config website
https://checkups.opster.com/checkup/input
-
Run in debug mode (foreground)
/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash" -e
-
Post data to Elastic (json format)
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/indexname/typename/optionalUniqueId" -d "{ \"Hello" : \"world\"}"
-
Read data to Elastic (json format)
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/_search" -d'{"query": { "match_all": {} }}'
-
Find specific data (json format)
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/_search" -d'{"query": {"query_string": {"query": "Hello"}}}'
-
List all indices
curl -X GET 'http://127.0.0.1:9200/_cat/indices/*?v&s=index'
-
Get last 1000 documents from an index
curl -X GET 'http://127.0.0.1:9200/myindex/_search?size=1000&pretty=true'
-
Get index info (ILM, ect...)
curl -X GET 'http://127.0.0.1:9200/myindex'
-
Retrieve all mappings on indices
curl -XGET http://localhost:9200/_all/_mapping
-
Get current usage of Elasticsearch threads
curl -XGET 'localhost:9600/_node/hot_threads?human=true'
-
Delete specific index
curl -X DELETE 'http://127.0.0.1:9200/graylog_deflector'
-
Unlock flood-state when disk is nearly full
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
-
Repair Elasticsearch wrong indexes with MongoDB
mongo --port 27017 --authenticationDatabase "graylog"
use graylog
show collections
db.index_ranges.drop()
exit
- Complex query (for listing last added data in index)
cat << EOF > query.json
{
"size": 1,
"sort": {"@timestamp":"desc"},
"query": {
"match_all": {}
}
}
EOF
curl -XPOST http://localhost:9200/index/_search -H 'Content-Type: application/json' -d @query.json