- Elasticsearch 7.0 Cookbook(Fourth Edition)
- Alberto Paro
- 194字
- 2021-06-24 14:52:29
How to do it...
The GET method allows us to return a document given its index, type, and ID.
The REST API URL is as follows:
http://<server>/<index_name>/_doc/<id>
To get a document, we will perform the following steps:
- If we consider the document that we indexed in the previous recipe, the call will be as follows:
GET /myindex/_doc/2qLrAfPVQvCRMe7Ku8r0Tw
- The result returned by Elasticsearch should be the indexed document:
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "2qLrAfPVQvCRMe7Ku8r0Tw",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"id" : "1234",
"date" : "2013-06-07T12:14:54",
"customer_id" : "customer1",
... truncated ...
}
}
- Our indexed data is contained in the _source parameter, but other information is returned:
-
- _index: The index that stores the document
- _type: The type of the document
- _id: The ID of the document
- _version: The version of the document
- found: Whether the document has been found
If the record is missing, a 404 error is returned as the status code, and the return JSON will be as follows:
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "2qLrAfPVQvCRMe7Kud8r0Tw",
"found" : false
}