/**
* Adds the given document to the search index
*
* @param \Elastica\Document $doc Document with data
* @return \Elastica\Response
*/
public function addDocument(Document $doc)
{
$path = urlencode($doc->getId());
$type = Request::PUT;
// If id is empty, POST has to be used to automatically create id
if (empty($path)) {
$type = Request::POST;
}
$options = $doc->getOptions(array('version', 'version_type', 'routing', 'percolate', 'parent', 'ttl', 'timestamp', 'op_type', 'consistency', 'replication', 'refresh', 'timeout'));
$response = $this->request($path, $type, $doc->getData(), $options);
$data = $response->getData();
// set autogenerated id to document
if (($doc->isAutoPopulate() || $this->getIndex()->getClient()->getConfigValue(array('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;
}