From 278889b5bd6e33cadbd5e28f77b94cc256ab6a17 Mon Sep 17 00:00:00 2001 From: Aaron Wells Date: Thu, 21 May 2015 14:36:32 +1200 Subject: [PATCH] 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 --- htdocs/lib/elastica/README.Mahara | 4 +++- htdocs/lib/elastica/lib/Elastica/Client.php | 6 +++++- htdocs/lib/elastica/lib/Elastica/Index.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/lib/elastica/README.Mahara b/htdocs/lib/elastica/README.Mahara index 2e6c455ebb..ac559455cc 100644 --- a/htdocs/lib/elastica/README.Mahara +++ b/htdocs/lib/elastica/README.Mahara @@ -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 diff --git a/htdocs/lib/elastica/lib/Elastica/Client.php b/htdocs/lib/elastica/lib/Elastica/Client.php index c5e56885cf..55c39435a4 100644 --- a/htdocs/lib/elastica/lib/Elastica/Client.php +++ b/htdocs/lib/elastica/lib/Elastica/Client.php @@ -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); diff --git a/htdocs/lib/elastica/lib/Elastica/Index.php b/htdocs/lib/elastica/lib/Elastica/Index.php index 1d2a78fddd..b8f1abfe03 100644 --- a/htdocs/lib/elastica/lib/Elastica/Index.php +++ b/htdocs/lib/elastica/lib/Elastica/Index.php @@ -145,7 +145,7 @@ class Index implements SearchableInterface $doc->setIndex($this->getName()); } - return $this->getClient()->addDocuments($docs); + return $this->getClient()->addDocuments($docs, $this); } /** -- GitLab