Get document

Introduced 1.0

After adding a JSON document to your index, you can use the get document API operation to retrieve the document’s information and data.

Example

  1. GET sample-index1/_doc/1

Path and HTTP methods

  1. GET <index>/_doc/<_id>
  2. HEAD <index>/_doc/<_id>
  1. GET <index>/_source/<_id>
  2. HEAD <index>/_source/<_id>

URL parameters

All get document URL parameters are optional.

ParameterTypeDescription
preferenceStringSpecifies a preference of which shard to retrieve results from. Available options are _local, which tells the operation to retrieve results from a locally allocated shard replica, and a custom string value assigned to a specific shard replica. By default, OpenSearch executes get document operations on random shards.
realtimeBooleanSpecifies whether the operation should run in realtime. If false, the operation waits for the index to refresh to analyze the source to retrieve data, which makes the operation near-realtime. Default is true.
refreshBooleanIf true, OpenSearch refreshes shards to make the get operation available to search results. Valid options are true, false, and wait_for, which tells OpenSearch to wait for a refresh before executing the operation. Default is false.
routingStringA value used to route the operation to a specific shard.
stored_fieldsBooleanWhether the get operation should retrieve fields stored in the index. Default is false.
_sourceStringWhether to include the _source field in the response body. Default is true.
_source_excludesStringA comma-separated list of source fields to exclude in the query response.
_source_includesStringA comma-separated list of source fields to include in the query response.
versionIntegerThe version of the document to return, which must match the current version of the document.
version_typeEnumRetrieves a specifically typed document. Available options are external (retrieve the document if the specified version number is greater than the document’s current version) and external_gte (retrieve the document if the specified version number is greater than or equal to the document’s current version). For example, to retrieve version 3 of a document, use /_doc/1?version=3&version_type=external.

Response

  1. {
  2. "_index": "sample-index1",
  3. "_id": "1",
  4. "_version": 1,
  5. "_seq_no": 0,
  6. "_primary_term": 9,
  7. "found": true,
  8. "_source": {
  9. "text": "This is just some sample text."
  10. }
  11. }

Response body fields

FieldDescription
_indexThe name of the index.
_idThe document’s ID.
_versionThe document’s version number. Updated whenever the document changes.
_seq_noThe sequnce number assigned when the document is indexed.
primary_termThe primary term assigned when the document is indexed.
foundWhether the document exists.
_routingThe shard that the document is routed to. If the document is not routed to a particular shard, this field is omitted.
_sourceContains the document’s data if found is true. If _source is set to false or stored_fields is set to true in the URL parameters, this field is omitted.
_fieldsContains the document’s data that’s stored in the index. Only returned if both stored_fields and found are true.