diff --git a/cmd/elastic.sh b/cmd/elastic.sh index 701c19c9..f627d279 100644 --- a/cmd/elastic.sh +++ b/cmd/elastic.sh @@ -5,7 +5,7 @@ function elastic_schema_drop(){ compose_run 'schema' node scripts/drop_index "$@ function elastic_schema_create(){ compose_run 'schema' ./bin/create_index; } function elastic_start(){ mkdir -p $DATA_DIR/elasticsearch - # attemp to set proper permissions if running as root + # Attempt to set proper permissions if running as root chown $DOCKER_USER $DATA_DIR/elasticsearch 2>/dev/null || true compose_exec up -d elasticsearch } @@ -24,11 +24,11 @@ function elastic_status(){ --output /dev/null \ --silent \ --write-out "%{http_code}" \ - "http://${ELASTIC_HOST:-localhost:9200}/_cluster/health?wait_for_status=yellow&timeout=1s" \ + "http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/_cluster/health?wait_for_status=yellow&timeout=1s" \ || true; } -# the same function but with a trailing newline +# Function to get HTTP status with a trailing newline, using optional port function elastic_status_newline(){ echo $(elastic_status); } register 'elastic' 'status' 'HTTP status code of the elasticsearch service' elastic_status_newline @@ -39,10 +39,10 @@ function elastic_wait(){ i=1 while [[ "$i" -le "$retry_count" ]]; do if [[ $(elastic_status) -eq 200 ]]; then - echo "Elasticsearch up!" + echo "Elasticsearch up on port ${ELASTIC_PORT:-9200}!" exit 0 elif [[ $(elastic_status) -eq 408 ]]; then - # 408 indicates the server is up but not yet yellow status + # 408 indicates the server is up but has not reached yellow status yet printf ":" else printf "." @@ -58,11 +58,13 @@ function elastic_wait(){ register 'elastic' 'wait' 'wait for elasticsearch to start up' elastic_wait -function elastic_info(){ curl -s "http://${ELASTIC_HOST:-localhost:9200}/"; } +# Function to get Elasticsearch version and build info with an optional port argument +function elastic_info(){ curl -s "http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/"; } register 'elastic' 'info' 'display elasticsearch version and build info' elastic_info +# Function to display a summary of document counts per source/layer with optional port function elastic_stats(){ - curl -s "http://${ELASTIC_HOST:-localhost:9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \ + curl -s "http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \ -H 'Content-Type: application/json' \ -d '{ "aggs": {