Skip to content

Commit 433839d

Browse files
authored
Merge pull request #854 from lonvia/fix-synonym-setup
Make sure to reopen the index when installation of synonym fails
2 parents 42e0c39 + 4f1d420 commit 433839d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/opensearch/src/main/java/de/komoot/photon/Server.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
1212
import org.opensearch.client.opensearch.OpenSearchClient;
1313
import org.opensearch.client.opensearch._types.HealthStatus;
14+
import org.opensearch.client.opensearch._types.OpenSearchException;
1415
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder;
1516
import org.slf4j.Logger;
1617

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

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

131-
(new IndexSettingBuilder()).setSynonymFile(synonymFile).updateIndex(client, PhotonIndex.NAME);
134+
try {
135+
(new IndexSettingBuilder()).setSynonymFile(synonymFile).updateIndex(client, PhotonIndex.NAME);
136+
} catch (OpenSearchException ex) {
137+
client.shutdown();
138+
throw new UsageException("Could not install synonyms: " + ex.getMessage());
139+
}
132140

133141
if (dbProperties.getLanguages() != null) {
134142
(new IndexMapping(dbProperties.getSupportStructuredQueries()))

app/opensearch/src/main/java/de/komoot/photon/opensearch/IndexSettingBuilder.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ public void updateIndex(OpenSearchClient client, String indexName) throws IOExce
4040
addDefaultSettings();
4141

4242
client.indices().close(req -> req.index(indexName));
43-
client.indices().putSettings(req -> req
44-
.index(indexName)
45-
.settings(s -> s.analysis(settings.build())));
46-
client.indices().open(req -> req.index(indexName));
43+
try {
44+
client.indices().putSettings(req -> req
45+
.index(indexName)
46+
.settings(s -> s.analysis(settings.build())));
47+
} finally {
48+
client.indices().open(req -> req.index(indexName));
49+
}
4750
}
4851

4952
public IndexSettingBuilder setSynonymFile(String synonymFile) throws IOException {

0 commit comments

Comments
 (0)