diff --git a/src/applications/search/config/PhabricatorSearchConfigOptions.php b/src/applications/search/config/PhabricatorSearchConfigOptions.php index 7b1f5b7076..398a285742 100644 --- a/src/applications/search/config/PhabricatorSearchConfigOptions.php +++ b/src/applications/search/config/PhabricatorSearchConfigOptions.php @@ -32,6 +32,10 @@ final class PhabricatorSearchConfigOptions ->setLocked(true) ->setDescription(pht('Elastic Search host.')) ->addExample('http://elastic.example.com:9200/', pht('Valid Setting')), + $this->newOption('search.elastic.namespace', 'string', 'phabricator') + ->setLocked(true) + ->setDescription(pht('Elastic Search index.')) + ->addExample('phabricator2', pht('Valid Setting')), ); } diff --git a/src/applications/search/engine/PhabricatorSearchEngineElastic.php b/src/applications/search/engine/PhabricatorSearchEngineElastic.php index 52b07bcaef..4960a307e9 100644 --- a/src/applications/search/engine/PhabricatorSearchEngineElastic.php +++ b/src/applications/search/engine/PhabricatorSearchEngineElastic.php @@ -2,10 +2,12 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine { private $uri; + private $index; private $timeout; - public function __construct($uri) { + public function __construct($uri, $index) { $this->uri = $uri; + $this->index = $index; } public function setTimeout($timeout) { @@ -51,7 +53,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine { } $this->executeRequest( - "/phabricator/{$type}/{$phid}/", + "/{$type}/{$phid}/", $spec, $is_write = true); } @@ -59,7 +61,7 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine { public function reconstructDocument($phid) { $type = phid_get_type($phid); - $response = $this->executeRequest("/phabricator/{$type}/{$phid}", array()); + $response = $this->executeRequest("/{$type}/{$phid}", array()); if (empty($response['exists'])) { return null; @@ -210,10 +212,10 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine { PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes()); } - // Don't use '/phabricator/_search' for the case that there is something + // Don't use '/_search' for the case that there is something // else in the index (for example if 'phabricator' is only an alias to - // some bigger index). - $uri = '/phabricator/'.implode(',', $types).'/_search'; + // some bigger index). Use '/$types/_search' instead. + $uri = '/'.implode(',', $types).'/_search'; try { $response = $this->executeRequest($uri, $this->buildSpec($query)); @@ -238,10 +240,10 @@ final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine { private function executeRequest($path, array $data, $is_write = false) { $uri = new PhutilURI($this->uri); + $uri->setPath($this->index); + $uri->appendPath($path); $data = json_encode($data); - $uri->setPath($path); - $future = new HTTPSFuture($uri, $data); if ($is_write) { $future->setMethod('PUT'); diff --git a/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php b/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php index 58049d5831..aa8757ead1 100644 --- a/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php +++ b/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php @@ -6,7 +6,8 @@ final class PhabricatorDefaultSearchEngineSelector public function newEngine() { $elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host'); if ($elastic_host) { - return new PhabricatorSearchEngineElastic($elastic_host); + $elastic_index = PhabricatorEnv::getEnvConfig('search.elastic.namespace'); + return new PhabricatorSearchEngineElastic($elastic_host, $elastic_index); } return new PhabricatorSearchEngineMySQL(); }