/** * Get the document from search index * * @param string $id Document id * @return Elastica_Document */ public function getDocument($id) { $path = $id; $result = $this->request($path, Elastica_Request::GET)->getData(); $document = new Elastica_Document($id, $result['_source'], $this->getType(), $this->getIndex()); $document->setVersion($result['_version']); return $document; }
/** * Get the document from search index * * @param string $id Document id * @return Elastica_Document */ public function getDocument($id) { $path = $id; try { $result = $this->request($path, Elastica_Request::GET)->getData(); } catch (Elastica_Exception_Response $e) { throw new Elastica_Exception_NotFound('doc id ' . $id . ' not found'); } if (empty($result['exists'])) { throw new Elastica_Exception_NotFound('doc id ' . $id . ' not found'); } $data = isset($result['_source']) ? $result['_source'] : array(); $document = new Elastica_Document($id, $data, $this->getName(), $this->getIndex()); $document->setVersion($result['_version']); return $document; }