/** * Adds the given document to the search index * * @param Elastica_Document $doc Document with data * @return Elastica_Response */ public function addDocument(Elastica_Document $doc) { $path = $doc->getId(); $query = array(); if ($doc->getVersion() > 0) { $query['version'] = $doc->getVersion(); } if (!is_null($doc->getParent())) { $query['parent'] = $doc->getParent(); } if ($doc->getOpType()) { $query['op_type'] = $doc->getOpType(); } if ($doc->getPercolate()) { $query['percolate'] = $doc->getPercolate(); } $type = Elastica_Request::PUT; // If id is empty, POST has to be used to automatically create id if (empty($path)) { $type = Elastica_Request::POST; } return $this->request($path, $type, $doc->getData(), $query); }