lib/Elastica/Type.php
public function getDocument($id, array $options = [])
    {
        $endpoint = new \Elasticsearch\Endpoints\Get();
        $endpoint->setID($id);
        $endpoint->setParams($options);

        $response = $this->requestEndpoint($endpoint);
        $result = $response->getData();

        if (!isset($result['found']) || false === $result['found']) {
            throw new NotFoundException('doc id '.$id.' not found');
        }

        if (isset($result['fields'])) {
            $data = $result['fields'];
        } elseif (isset($result['_source'])) {
            $data = $result['_source'];
        } else {
            $data = [];
        }

        $document = new Document($id, $data, $this->getName(), $this->getIndex());
        $document->setVersion($result['_version']);

        return $document;
    }
public function getDocument($id, array $options = [])
    {
        $endpoint = new \Elasticsearch\Endpoints\Get();
        $endpoint->setID($id);
        $endpoint->setParams($options);

        $response = $this->requestEndpoint($endpoint);
        $result = $response->getData();

        if (!isset($result['found']) || false === $result['found']) {
            throw new NotFoundException('doc id '.$id.' not found');
        }

        if (isset($result['fields'])) {
            $data = $result['fields'];
        } elseif (isset($result['_source'])) {
            $data = $result['_source'];
        } else {
            $data = [];
        }

        $document = new Document($id, $data, $this->getName(), $this->getIndex());
        $document->setVersion($result['_version']);

        return $document;
    }
public function getDocument ( $ id , array $ options = [ ] ) { $ endpoint = new \ Elasticsearch \ Endpoints \ Get ( ) ; $ endpoint -> setID ( $ id ) ; $ endpoint -> setParams ( $ options ) ; $ response = $ this -> requestEndpoint ( $ endpoint ) ; $ result = $ response -> getData ( ) ; if ( ! isset ( $ result [ 'found' ] ) || false === $ result [ 'found' ] ) { throw new NotFoundException ( 'doc id ' . $ id . ' not found' ) ; } if ( isset ( $ result [ 'fields' ] ) ) { $ data = $ result [ 'fields' ] ; } elseif ( isset ( $ result [ '_source' ] ) ) { $ data = $ result [ '_source' ] ; } else { $ data = [ ] ; } $ document = new Document ( $ id , $ data , $ this -> getName ( ) , $ this -> getIndex ( ) ) ; $ document -> setVersion ( $ result [ '_version' ] ) ; return $ document ; }
Get the document from search index.

@param int|string $id      Document id
@param array      $options options for the get request

@throws \Elastica\Exception\NotFoundException
@throws \Elastica\Exception\ResponseException

@return \Elastica\Document
Get the document from search index .