lib/Elastica/Type.php
public function addDocument(Document $doc)
    {
        $endpoint = new \Elasticsearch\Endpoints\Index();

        if (null !== $doc->getId() && '' !== $doc->getId()) {
            $endpoint->setID($doc->getId());
        }

        $options = $doc->getOptions(
            [
                'version',
                'version_type',
                'routing',
                'percolate',
                'parent',
                'op_type',
                'consistency',
                'replication',
                'refresh',
                'timeout',
                'pipeline',
            ]
        );

        $endpoint->setBody($doc->getData());
        $endpoint->setParams($options);

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

        $data = $response->getData();
        // set autogenerated id to document
        if (($doc->isAutoPopulate()
                || $this->getIndex()->getClient()->getConfigValue(['document', 'autoPopulate'], false))
            && $response->isOk()
        ) {
            if (!$doc->hasId()) {
                if (isset($data['_id'])) {
                    $doc->setId($data['_id']);
                }
            }
            if (isset($data['_version'])) {
                $doc->setVersion($data['_version']);
            }
        }

        return $response;
    }
public function addDocument(Document $doc)
    {
        $endpoint = new \Elasticsearch\Endpoints\Index();

        if (null !== $doc->getId() && '' !== $doc->getId()) {
            $endpoint->setID($doc->getId());
        }

        $options = $doc->getOptions(
            [
                'version',
                'version_type',
                'routing',
                'percolate',
                'parent',
                'op_type',
                'consistency',
                'replication',
                'refresh',
                'timeout',
                'pipeline',
            ]
        );

        $endpoint->setBody($doc->getData());
        $endpoint->setParams($options);

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

        $data = $response->getData();
        // set autogenerated id to document
        if (($doc->isAutoPopulate()
                || $this->getIndex()->getClient()->getConfigValue(['document', 'autoPopulate'], false))
            && $response->isOk()
        ) {
            if (!$doc->hasId()) {
                if (isset($data['_id'])) {
                    $doc->setId($data['_id']);
                }
            }
            if (isset($data['_version'])) {
                $doc->setVersion($data['_version']);
            }
        }

        return $response;
    }
public function addDocument ( Document $ doc ) { $ endpoint = new \ Elasticsearch \ Endpoints \ Index ( ) ; if ( null !== $ doc -> getId ( ) && '' !== $ doc -> getId ( ) ) { $ endpoint -> setID ( $ doc -> getId ( ) ) ; } $ options = $ doc -> getOptions ( [ 'version' , 'version_type' , 'routing' , 'percolate' , 'parent' , 'op_type' , 'consistency' , 'replication' , 'refresh' , 'timeout' , 'pipeline' , ] ) ; $ endpoint -> setBody ( $ doc -> getData ( ) ) ; $ endpoint -> setParams ( $ options ) ; $ response = $ this -> requestEndpoint ( $ endpoint ) ; $ data = $ response -> getData ( ) ; // set autogenerated id to document if ( ( $ doc -> isAutoPopulate ( ) || $ this -> getIndex ( ) -> getClient ( ) -> getConfigValue ( [ 'document' , 'autoPopulate' ] , false ) ) && $ response -> isOk ( ) ) { if ( ! $ doc -> hasId ( ) ) { if ( isset ( $ data [ '_id' ] ) ) { $ doc -> setId ( $ data [ '_id' ] ) ; } } if ( isset ( $ data [ '_version' ] ) ) { $ doc -> setVersion ( $ data [ '_version' ] ) ; } } return $ response ; }
Adds the given document to the search index.

@param \Elastica\Document $doc Document with data

@return \Elastica\Response
Adds the given document to the search index .