Commit 278889b5 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon
Browse files

elasticsearch: Add index name to _bulk command path

Bug 1457709: We only do this when the command comes
from an Index object itself, which means that all the
data in the bulk request will have the same index anyway.

You'll still need to set rest.action.multi.allow_explicit_index:false
in your config.yml, or else the data will be able to override the
index name in the URL.

See https://www.elastic.co/guide/en/elasticsearch/reference/current/url-access-control.html

Change-Id: I2f441bd3613e3c3195c88609989d122e6e26de76
parent abb2dad5
......@@ -8,4 +8,6 @@ This library is used for for interfacing with an elasticsearch server.
Changes:
* Removed build & test files not needed for Mahara.
\ No newline at end of file
* Removed build & test files not needed for Mahara.
* Added an option to do include the Elasticsearch Index in the URL for bulk addDocument calls
\ No newline at end of file
......@@ -291,15 +291,19 @@ class Client
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
*
* @param array|\Elastica\Document[] $docs Array of Elastica\Document
* @param string|\Elastica\Index (Optional) If all of the documents are for the same index
* @return \Elastica\Bulk\ResponseSet Response object
*/
public function addDocuments(array $docs)
public function addDocuments(array $docs, Index $index = null)
{
if (empty($docs)) {
throw new InvalidException('Array has to consist of at least one element');
}
$bulk = new Bulk($this);
if ($index) {
$bulk->setIndex($index);
}
$bulk->addDocuments($docs);
......
......@@ -145,7 +145,7 @@ class Index implements SearchableInterface
$doc->setIndex($this->getName());
}
return $this->getClient()->addDocuments($docs);
return $this->getClient()->addDocuments($docs, $this);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment