Elasticsearch supports RESTful APIs, which allows you to use HTTP APIs to perform add, delete, modify, and search operations and configure aliases. This topic describes how to use RESTful APIs.

References from open-source Elasticsearch documentation

Use Java REST Client to access clusters

Only access over HTTP and TCP is supported. We recommend that you use Java REST Client.

Use the Java API to access clusters

Elasticsearch is preinstalled with Transport Client and Java REST Client for Java users. Transport Client falls into disuse in Elasticsearch 7.0 and is no longer available in Elasticsearch 8.0. We recommend that you use Java REST Client. For more information about the Java API, see Java API and Overview.
Note The version of Elasticsearch used by Java REST Client must match that of the Elasticsearch cluster. Otherwise, Java REST Client may fail to identify the Elasticsearch cluster.

RESTful API (HTTP) request parameters

You can use RESTful APIs or curl commands to communicate with Elasticsearch through port 9200.

Note Open-source Elasticsearch provides clients for several languages, such as Groovy, JavaScript, .NET, PHP, Perl, Python, and Ruby. The Elastic community also provides many clients and plug-ins. For more information, see Community Contributed Clients.

A curl command over HTTP consists of the following parts:

curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>? <QUERY_STRING>' -d '<BODY>'
Parameter Description
VERB An HTTP method. GET, POST, PUT, HEAD, and DELETE are supported.
PROTOCOL http or https. Use https only if HTTPS is enabled for Elasticsearch.
HOST The hostname of a node in your Elasticsearch cluster. If you use the local node, set this field to localhost.
PORT The port over which the Elasticsearch HTTP service runs. The default port number is 9200.
PATH The API operation. For example, _count returns the number of documents in a cluster. PATH can contain multiple components, such as _cluster/stats and _nodes/stats/jvm.
QUERY_STRING Optional. A query parameter. For example, the ? pretty parameter ensures that the JSON-format data returned by the request is more readable.
BODY Optional. The JSON-format request body.

RESTful API over HTTP

Run the following command to calculate the number of documents in an Elasticsearch cluster:
curl -XGET 'http://localhost:9200/_count?pretty' -d '
{ 
  "query": { 
    "match_all": {} 
  }
}'
The following result is returned:
{ 
    "count" : 0, 
    "_shards" : { 
        "total" : 5, 
        "successful" : 5, 
        "failed" : 0 
     }
}

You can use the curl -i command to retrieve the HTTP header, for example, curl -i -XGET 'localhost:9200/'.

curl -XGET 'localhost:9200/_count? pretty' -d '
{ 
    "query": { 
        "match_all": {} 
    }
}'
The following command is a shorthand for the request:
GET /_count
{ 
    "query": { 
        "match_all": {} 
    }
}