Health Check Cheat-Sheet
Health Check Cheat-Sheet
curl localhost:9200/_cluster/health?pretty
curl localhost:9200/_cluster/allocation/explain?pretty
curl localhost:9200/_cluster/settings?pretty
We’re deleting data based on a search and running the deletion as a task as data might be huge.
curl -X GET
"localhost:9200/_tasks?detailed=true&actions=*/delete/byquery&pretty"
Get Data Stats of a specific Node such as count of Indices on it:
curl localhost:9200/_nodes/NODE_NAME/stats?pretty
curl localhost:9200/_nodes/stats
delete index
You can query using parameters on the URL. But you can also use JSON, as shown in the next
example. JSON would be easier to read and debug when you have a complex query than one
giant string of URL parameters.
All Elasticsearch fields are indexes. So this lists all fields and their types in an index.
Add Data
Here is how to add fields to an existing document. First we create a new one. Then we update it.
backup index
export pwd="elastic:"
For an nginx web server this produces web hit counts by user city:
}
}
}
}
'
This expands that to product response code count by city in an nginx web server log
curl -XGET --user $pwd --header 'Content-Type: application/json'
https://58571402f5464923883e7be42a037917.eu-central-1.aws.cloud.es.io:9243/
logstash/_search?pretty -d '{
"aggs": {
"city": {
"terms": {
"field": "geoip.city_name.keyword"
},
"aggs": {
"responses": {
"terms": {
"field": "response"
}
}
}
},
"responses": {
"terms": {
"field": "response"
}
}
}
}'
If you have turned on security with ElasticSearch then you need to supply the user and password
like shown below to every curl command:
Pretty Print
Add ?pretty=true to any search to pretty print the JSON. Like this:
To return only certain fields put them into the _source array:
GET filebeat-7.6.2-2020.05.05-000001/_search
{
"_source":
["suricata.eve.timestamp","source.geo.region_name","event.created"],
"query": {
"match" : { "source.geo.country_iso_code": "GR" }
}
}
To Query by Date
When the field is of type date you can use date math, like this:
GET filebeat-7.6.2-2020.05.05-000001/_search
{
"query": {
"range" : {
"event.created": {
"gte" : "now-7d/d"
}
}
}
}
Взято отсюда https://www.bmc.com/blogs/elasticsearch-commands/