How to check Elasticsearch version from the command line

Introduction
If you store data in Elasticsearch, you may encounter situations where you need to know the version of the product you are running. There are many reasons why you need to know the version. You may need to check to see if you need to upgrade, or you may need to ensure compatibility with other components of the Resilient Stack. Regardless of the reason you need the version, Elasticsearch can easily determine the version. In this tutorial, you will learn two easy ways to check your Elasticsearch version from the command line.
Prerequisites
Before attempting to check the version of Elasticsearch, you need to have some key prerequisites. Minimum system requirements:
make sure that Elasticsearch is installed and running.
To check if Elasticsearch is running, execute the following command in the terminal:
curl http://localhost:9200/_cluster/health?pretty
You should receive output containing information about the Elasticsearch instance.
# curl http://localhost:9200/_cluster/health?pretty
{   "cluster_name": "elasticsearch",   "status": "yellow",   "timed_out": false,   "number_of_nodes": 1,   "number_of_data_nodes": 1,   "active_primary_shards": 37,





















curl -XGET'http://localhost:9200'
In this example, Elasticsearch is running locally on the default port, so our HTTP request will be http://localhost:9200. If Elasticsearch is running on another server, your HTTP request will take the form http://YOURDOMAIN.com:9200.
The following results contain some information about Elasticsearch, including the version number. In this example, the result shows that our Elasticsearch version is 7.8.0:
# curl -XGET'http://localhost:9200'
{   "name": "suricata",   "cluster_name": "elasticsearch",   "cluster_uuid": "rFagDb6gRuaKl69f5KkJMA",   "version": {     "number": "7.8.0",     "build_flavor": "default",     "build_type": "rpm",     "build_hash": "757314695644ea9a1dc2fecd26d1a43856725e65",










    "lucene_version": "8.5.1",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}
Note: If the output is The displayed version number is different from the installed version number, you may have multiple Elasticsearch installed on your computer.
Option 2: Use elasticsearch -version to check the version
In addition to using the previous command, you can also just start Elasticsearch to find the version number. When Elasticsearch starts, it will output the version number. However, it also outputs a lot of other information, so it may be difficult to sort the output to find it. You can use the version tag when starting Elasticsearch to eliminate confusion and get version information directly. The following example shows how to run commands on MacOS. The specific command syntax will depend on your operating system:
bin/elasticsearch --version The
output includes our version information, as shown below:
# /usr/share/elasticsearch/bin/elasticsearch --version
Version: 7.8.0, Build :
Again, you can easily see that the installed version of Elasticsearch is 7.8.0.
Conclusion
When using Elasticsearch, it is sometimes necessary to check the version of the product-it may be to check compatibility with other components of Elastic Stack, or it may be to check whether it needs to be upgraded. Fortunately, it is easy to check your Elasticsearch version using the above two methods. Through these step-by-step instructions, you will have a basic understanding of curl functions and command line tools to obtain the information you need.

Guess you like

Origin blog.csdn.net/allway2/article/details/108869530