How to get JUST the Elasticsearch server version f

2019-07-13 08:20发布

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"
    }
}

2条回答
Emotional °昔
2楼-- · 2019-07-13 08:37

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"])'
查看更多
祖国的老花朵
3楼-- · 2019-07-13 08:51

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
查看更多
登录 后发表回答