Skip to content

Instantly share code, notes, and snippets.

@maxmanders
Last active June 28, 2021 11:01
Show Gist options
  • Save maxmanders/94b4fd82fce70fbaec6c0adafea70224 to your computer and use it in GitHub Desktop.
Save maxmanders/94b4fd82fce70fbaec6c0adafea70224 to your computer and use it in GitHub Desktop.
Some useful shell functions for those ElasticSearch queries you never remember
#!/usr/bin/env bash
es_get_endpoint() {
local domain_name
local endpoint
domain_name="${1}"
endpoint="$(aws es describe-elasticsearch-domain --domain-name ${domain_name} --query 'DomainStatus.Endpoints.vpc' | tr -d '"')"
if [ "${endpoint}" = "null" ]; then
endpoint="$(aws es describe-elasticsearch-domain --domain-name ${domain_name} --query 'DomainStatus.Endpoint' | tr -d '"')"
fi
echo -n "${endpoint}"
}
es_get_disk_usage() {
local domain_name
domain_name="${1}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/_cat/allocation?v&pretty"
}
es_get_index_usage() {
local domain_name
domain_name="${1}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/_cat/indices?v&pretty"
}
es_get_index_usage() {
local domain_name
domain_name="${1}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/_cat/indices?v&pretty"
}
es_get_cluster_health() {
local domain_name
domain_name="${1}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/_cluster/health?pretty"
}
es_get_cluster_state() {
local domain_name
domain_name="${1}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/_cluster/state?pretty"
}
es_list_indices() {
local domain_name
domain_name="${1}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/_cat/indices?v&pretty"
}
es_get_index() {
local domain_name
local index
domain_name="${1}"
index="${2}"
curl --silent --request GET "$(es_get_endpoint ${domain_name})/${index}?pretty"
}
@maxmanders
Copy link
Author

Needs some additional logic to get the endpoint from a different JMESPath expression for non-VPC clusters: .DomainStatus.Endpoints.vpc vs .DomainStatus.Endpoint.

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment