How to get JUST the Elasticsearch server version from the command line

末鹿安然 提交于 2019-12-10 18:38:10

问题


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

回答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"])'



回答2:


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


来源:https://stackoverflow.com/questions/34822244/how-to-get-just-the-elasticsearch-server-version-from-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!