Skip to content

Get Document API

Edit page

The Get API allows to get a document from the index based on its ID. The following example gets a document from an index called “twitter”, with ID valued 1:

GET /twitter/tweet/1

The result of the above get operation is a 200 OK HTTP response code with the following body:

{
"user": "Kronuz",
"post_date": "2019-03-22T14:35:26",
"message": "Trying out Xapiand",
"_id": 1,
"_version": 1
}

The above result includes the _id and _version of the document we wish to retrieve, additionally to the actual body of the document.

If the document is not found, it will return a 404 Not Found HTTP response code.

By passing the comments query param (or starting the node with --comments, which -vvvv implies), the result carries the engine’s bookkeeping too: #docid is the document’s number in the index and #shard the shard that holds it.

GET /twitter/tweet/1?comments=true

A selector keeps one part of the document. Pass it in the selector query param, or after the ID, as in GET /twitter/tweet/1.user:

GET /twitter/tweet/1?selector=user

By passing the volatile query param to the request, the operation opens the index for writing, so the read sees the latest view the writer has.

Sources: src/server/search_views.cc:1834-1889 (the get and the #docid, #shard fields, only with request.comments), src/opts.cc:252-255 (--comments), and src/server/search_views.cc:2371-2380 (volatile).