Is there way to get JUST the version number for an Elasticsearch server. I know you get the JSON request data but is there a way to parse that request get the version number only.
curl localhost:9200
{
...
"version": {
...
"number": "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"])'
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