How to get JUST the Elasticsearch server version from the command line
Another way that doesn't require any outside dependencies is to use response filtering and the filter_path
query string parameter (available since ES 1.6) and the awk
command.
curl -s -XGET 'localhost:9200?filter_path=version.number&pretty=false' | awk -F'"' {'print $6'}
That returns:
2.1.1
If you have the jq
utility, you can use it to parse the json reply and output a plain text string:
curl -sS localhost:9200 | jq -r .version.number
General purpose scripting languages can accomplish the same, but are usually more clunky:
curl -sS localhost:9200 | python -c 'import json, sys; print(json.loads(sys.stdin.read())["version"]["number"])'