Elasticsearch REST API and Dev Tools

Elasticsearch has no special desktop screen. Every action travels as an HTTP request, the same kind of message a browser sends to open a web page. Learn the request pattern once, and every feature in the course follows the same shape. Programming languages, command-line tools, and Kibana all use this one doorway.

Anatomy of a Request

A request has four parts: a method, an address, optional parameters, and an optional JSON body. The method says what to do. The address says where to do it. The body carries the details.

  METHOD   ADDRESS                      PARAMETERS      BODY
  ───────  ───────────────────────────  ──────────────  ─────────────────────
  GET      /products/_search            ?pretty         { "query": { ... } }

  Meaning: "Search the products index and print the answer neatly"

HTTP Methods

MethodPurposeExample
GETRead data or run a searchGET /products/_doc/1
PUTCreate or replace something at a known addressPUT /products
POSTAdd data or run an actionPOST /products/_doc
DELETERemove an index or documentDELETE /products/_doc/1
HEADCheck existence without a bodyHEAD /products

Using Kibana Dev Tools

Kibana includes a console built for Elasticsearch requests. Open the main menu, choose Dev Tools, and type a request in the left panel. Press Ctrl+Enter (Cmd+Enter on a Mac) to send it. The right panel shows the formatted answer. The console suggests endpoint names and field names as you type, and it adds authentication automatically.

GET /_cluster/health

PUT /books
{
  "settings": { "number_of_shards": 1 }
}

GET /books/_search
{
  "query": { "match_all": {} }
}

The examples across this course use the Dev Tools format. Each block starts with the method and path, followed by the JSON body on the next lines.

Using curl from a Terminal

The same request works in a terminal through curl. Version 8 and later enables HTTPS and passwords by default, so the command carries credentials and the certificate file.

curl --cacert http_ca.crt -u elastic:YOUR_PASSWORD \
  -X GET "https://localhost:9200/books/_search?pretty" \
  -H "Content-Type: application/json" \
  -d '{ "query": { "match_all": {} } }'

Replace YOUR_PASSWORD with the password created during installation. Never paste real passwords into shared documents or public repositories.

Reading a Response

Search answers arrive as JSON. A handful of fields carry most of the useful information.

{
  "took": 4,                      ← milliseconds spent on the search
  "timed_out": false,
  "_shards": { "total": 1, "successful": 1, "failed": 0 },
  "hits": {
    "total": { "value": 2, "relation": "eq" },   ← number of matches
    "max_score": 1.0,
    "hits": [
      { "_index": "books", "_id": "1", "_score": 1.0,
        "_source": { "title": "Learning Search" } }
    ]
  }
}

The "hits.hits" list holds the matching documents. Each entry shows the index name, the document ID, the relevance score, and the original data under "_source."

Helpful URL Parameters

ParameterEffect
?prettyFormats JSON with line breaks for easy reading
?vAdds column headers to _cat output
?filter_path=hits.hits._sourceTrims the response to the chosen fields
?format=jsonSwitches _cat output from text to JSON
?humanShows sizes like 5mb instead of raw bytes

The _cat APIs

The _cat family prints compact tables for people instead of JSON for programs. These endpoints answer common health questions in one line.

GET /_cat/health?v
GET /_cat/indices?v
GET /_cat/nodes?v
GET /_cat/shards?v

Sample output of /_cat/indices?v:

health status index  pri rep docs.count store.size
green  open   books    1   1          2      9.8kb

Status Codes

CodeMeaningCommon Cause
200SuccessSearch or read worked
201CreatedNew document or index added
400Bad requestBroken JSON or invalid query
401UnauthorizedMissing or wrong credentials
404Not foundIndex or document does not exist
409ConflictVersion clash on update

A 400 error includes a "reason" message that names the exact problem. Read that message before changing anything. It usually points to the misspelled field or the missing bracket.

Habits That Prevent Mistakes

Small details cause most beginner errors. A missing comma in the JSON body produces a 400 response. A wrong index name produces a 404. Check the spelling of the path first, and validate the JSON body with a formatter when a request fails without an obvious reason.

Keep destructive requests under control. A DELETE on an index name removes every document in it, and no undo button exists. Type the full index name instead of a wildcard, and confirm the target with a GET request before deleting anything on a shared cluster.

Safe habit:

  GET  /products/_count        ← confirm this is the right index
  DELETE /products             ← run only after confirming

Save frequently used requests inside Kibana Dev Tools. The console remembers the history, and a collection of working examples becomes a personal reference library that grows with every project.