Skip to content

Commit

Permalink
make sure to reopen the index when installation of synonym fails
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Nov 29, 2024
1 parent 42e0c39 commit 4f1d420
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 9 additions & 1 deletion app/opensearch/src/main/java/de/komoot/photon/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch._types.HealthStatus;
import org.opensearch.client.opensearch._types.OpenSearchException;
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder;
import org.slf4j.Logger;

Expand Down Expand Up @@ -126,9 +127,16 @@ public DatabaseProperties recreateIndex(String[] languages, Date importDate, boo
}

public void updateIndexSettings(String synonymFile) throws IOException {
// This ensures we are on the right version. Do not mess with the
// database if the version does not fit.
var dbProperties = loadFromDatabase();

(new IndexSettingBuilder()).setSynonymFile(synonymFile).updateIndex(client, PhotonIndex.NAME);
try {
(new IndexSettingBuilder()).setSynonymFile(synonymFile).updateIndex(client, PhotonIndex.NAME);
} catch (OpenSearchException ex) {
client.shutdown();
throw new UsageException("Could not install synonyms: " + ex.getMessage());
}

if (dbProperties.getLanguages() != null) {
(new IndexMapping(dbProperties.getSupportStructuredQueries()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ public void updateIndex(OpenSearchClient client, String indexName) throws IOExce
addDefaultSettings();

client.indices().close(req -> req.index(indexName));
client.indices().putSettings(req -> req
.index(indexName)
.settings(s -> s.analysis(settings.build())));
client.indices().open(req -> req.index(indexName));
try {
client.indices().putSettings(req -> req
.index(indexName)
.settings(s -> s.analysis(settings.build())));
} finally {
client.indices().open(req -> req.index(indexName));
}
}

public IndexSettingBuilder setSynonymFile(String synonymFile) throws IOException {
Expand Down

0 comments on commit 4f1d420

Please sign in to comment.