Page MenuHomePhabricator

D9798.id23517.diff
No OneTemporary

D9798.id23517.diff

diff --git a/conf/default.conf.php b/conf/default.conf.php
--- a/conf/default.conf.php
+++ b/conf/default.conf.php
@@ -761,6 +761,10 @@
// 'http://elastic.example.com:9200/' here.
'search.elastic.host' => null,
+ // Similar to storage.default-namespace, this allows configuration of the
+ // index that Phabricator will use for Elasticsearch.
+ 'search.elastic.index' => 'phabricator',
+
// Phabricator uses a search engine selector to choose which search engine
// to use when indexing and reconstructing documents, and when executing
// queries. You can override the engine selector to provide a new selector
diff --git a/src/applications/search/config/PhabricatorSearchConfigOptions.php b/src/applications/search/config/PhabricatorSearchConfigOptions.php
--- a/src/applications/search/config/PhabricatorSearchConfigOptions.php
+++ b/src/applications/search/config/PhabricatorSearchConfigOptions.php
@@ -32,6 +32,10 @@
->setLocked(true)
->setDescription(pht('Elastic Search host.'))
->addExample('http://elastic.example.com:9200/', pht('Valid Setting')),
+ $this->newOption('search.elastic.index', '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
--- 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 @@
}
$this->executeRequest(
- "/phabricator/{$type}/{$phid}/",
+ "/{$type}/{$phid}/",
$spec,
$is_write = true);
}
@@ -59,7 +61,7 @@
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;
@@ -207,10 +209,10 @@
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));
@@ -234,7 +236,7 @@
}
private function executeRequest($path, array $data, $is_write = false) {
- $uri = new PhutilURI($this->uri);
+ $uri = new PhutilURI($this->uri.$this->index);
$data = json_encode($data);
$uri->setPath($path);
diff --git a/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php b/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php
--- a/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php
+++ b/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php
@@ -9,7 +9,8 @@
public function newEngine() {
$elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host');
if ($elastic_host) {
- return new PhabricatorSearchEngineElastic($elastic_host);
+ $elastic_index = PhabricatorEnv::getEnvConfig('search.elastic.index');
+ return new PhabricatorSearchEngineElastic($elastic_host, $elastic_index);
}
return new PhabricatorSearchEngineMySQL();
}

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 2, 12:50 PM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7729475
Default Alt Text
D9798.id23517.diff (4 KB)

Event Timeline