Skip to content

Commit 66a3abe

Browse files
Chad Horohoeepriestley
authored andcommitted
Make it possible to configure Elasticsearch index name
Summary: Similar to storage.default-namespace sometimes during development you'll want to handle multiple indexes alongside one another. Rather than hardcoding the /phabricator/ index make this exposed in new search.elastic.index setting, defaulting to the existing "phabricator" Test Plan: Existing installations should be unaffected by this change. Changing the new setting will result in new indexes being created when someone runs `./bin/search index` again Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: 20after4, rush898, epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9798
1 parent 793eced commit 66a3abe

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/applications/search/config/PhabricatorSearchConfigOptions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function getOptions() {
3232
->setLocked(true)
3333
->setDescription(pht('Elastic Search host.'))
3434
->addExample('http://elastic.example.com:9200/', pht('Valid Setting')),
35+
$this->newOption('search.elastic.namespace', 'string', 'phabricator')
36+
->setLocked(true)
37+
->setDescription(pht('Elastic Search index.'))
38+
->addExample('phabricator2', pht('Valid Setting')),
3539
);
3640
}
3741

src/applications/search/engine/PhabricatorSearchEngineElastic.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
final class PhabricatorSearchEngineElastic extends PhabricatorSearchEngine {
44
private $uri;
5+
private $index;
56
private $timeout;
67

7-
public function __construct($uri) {
8+
public function __construct($uri, $index) {
89
$this->uri = $uri;
10+
$this->index = $index;
911
}
1012

1113
public function setTimeout($timeout) {
@@ -51,15 +53,15 @@ public function reindexAbstractDocument(
5153
}
5254

5355
$this->executeRequest(
54-
"/phabricator/{$type}/{$phid}/",
56+
"/{$type}/{$phid}/",
5557
$spec,
5658
$is_write = true);
5759
}
5860

5961
public function reconstructDocument($phid) {
6062
$type = phid_get_type($phid);
6163

62-
$response = $this->executeRequest("/phabricator/{$type}/{$phid}", array());
64+
$response = $this->executeRequest("/{$type}/{$phid}", array());
6365

6466
if (empty($response['exists'])) {
6567
return null;
@@ -210,10 +212,10 @@ public function executeSearch(PhabricatorSavedQuery $query) {
210212
PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes());
211213
}
212214

213-
// Don't use '/phabricator/_search' for the case that there is something
215+
// Don't use '/_search' for the case that there is something
214216
// else in the index (for example if 'phabricator' is only an alias to
215-
// some bigger index).
216-
$uri = '/phabricator/'.implode(',', $types).'/_search';
217+
// some bigger index). Use '/$types/_search' instead.
218+
$uri = '/'.implode(',', $types).'/_search';
217219

218220
try {
219221
$response = $this->executeRequest($uri, $this->buildSpec($query));
@@ -238,10 +240,10 @@ public function executeSearch(PhabricatorSavedQuery $query) {
238240

239241
private function executeRequest($path, array $data, $is_write = false) {
240242
$uri = new PhutilURI($this->uri);
243+
$uri->setPath($this->index);
244+
$uri->appendPath($path);
241245
$data = json_encode($data);
242246

243-
$uri->setPath($path);
244-
245247
$future = new HTTPSFuture($uri, $data);
246248
if ($is_write) {
247249
$future->setMethod('PUT');

src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ final class PhabricatorDefaultSearchEngineSelector
66
public function newEngine() {
77
$elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host');
88
if ($elastic_host) {
9-
return new PhabricatorSearchEngineElastic($elastic_host);
9+
$elastic_index = PhabricatorEnv::getEnvConfig('search.elastic.namespace');
10+
return new PhabricatorSearchEngineElastic($elastic_host, $elastic_index);
1011
}
1112
return new PhabricatorSearchEngineMySQL();
1213
}

0 commit comments

Comments
 (0)