Issue
The following ElasticsearchException is thrown during the upgrade process, causing the upgrade to fail, but the Elasticsearch server is not necessary during it
How can avoid this error?
2023-02-07 11:21:22.931 ERROR [main][ElasticsearchSearchEngine:56] bundle com.liferay.portal.search.elasticsearch7.impl:6.0.63 (687)[com.liferay.portal.search.elasticsearch7.internal.ElasticsearchSearchEngine(3560)] : The activate method has thrown an exception
java.lang.RuntimeException: org.elasticsearch.ElasticsearchException: ElasticsearchException[java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused]; nested: ExecutionException[java.net.ConnectException: Connection refused]; nested: ConnectException[Connection refused];
at org.elasticsearch.client.RestHighLevelClient.performClientRequest(RestHighLevelClient.java:2695) ~[?:?]
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:2171) ~[?:?]
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:2137) ~[?:?]
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:2105) ~[?:?]
at org.elasticsearch.client.ClusterClient.health(ClusterClient.java:151) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.HealthClusterRequestExecutorImpl._getClusterHealthResponse(HealthClusterRequestExecutorImpl.java:98) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.HealthClusterRequestExecutorImpl.execute(HealthClusterRequestExecutorImpl.java:49) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.ElasticsearchClusterRequestExecutor.executeClusterRequest(ElasticsearchClusterRequestExecutor.java:53) ~[?:?]
at com.liferay.portal.search.engine.adapter.cluster.HealthClusterRequest.accept(HealthClusterRequest.java:40) ~[?:?]
at com.liferay.portal.search.engine.adapter.cluster.HealthClusterRequest.accept(HealthClusterRequest.java:22) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.cluster.ElasticsearchClusterRequestExecutor.execute(ElasticsearchClusterRequestExecutor.java:46) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.search.engine.adapter.ElasticsearchSearchEngineAdapterImpl.execute(ElasticsearchSearchEngineAdapterImpl.java:69) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.ElasticsearchSearchEngine._waitForYellowStatus(ElasticsearchSearchEngine.java:396) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.ElasticsearchSearchEngine.initialize(ElasticsearchSearchEngine.java:134) ~[?:?]
at com.liferay.portal.search.elasticsearch7.internal.ElasticsearchSearchEngine.activate(ElasticsearchSearchEngine.java:234) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
[...omitted...]
at com.liferay.portal.bootstrap.ModuleFrameworkImpl._registerService(ModuleFrameworkImpl.java:1271) ~[com.liferay.portal.bootstrap.jar:?]
at com.liferay.portal.bootstrap.ModuleFrameworkImpl.lambda$_registerApplicationContext$4(ModuleFrameworkImpl.java:1223) ~[com.liferay.portal.bootstrap.jar:?]
at java.util.Iterator.forEachRemaining(Iterator.java:116) [?:1.8.0_171]
at com.liferay.portal.bootstrap.ModuleFrameworkImpl._registerApplicationContext(ModuleFrameworkImpl.java:1210) [com.liferay.portal.bootstrap.jar:?]
at com.liferay.portal.bootstrap.ModuleFrameworkImpl.registerContext(ModuleFrameworkImpl.java:256) [com.liferay.portal.bootstrap.jar:?]
at com.liferay.portal.module.framework.ModuleFrameworkUtil.registerContext(ModuleFrameworkUtil.java:41) [portal-impl.jar:?]
at com.liferay.portal.util.InitUtil.registerContext(InitUtil.java:301) [portal-impl.jar:?]
at com.liferay.portal.tools.DBUpgrader.main(DBUpgrader.java:138) [portal-impl.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
at com.liferay.portal.tools.db.upgrade.client.DBUpgraderLauncher.main(DBUpgraderLauncher.java:54) [com.liferay.portal.tools.db.upgrade.client.jar:?]
Environment
- Any Liferay DXP version
Resolution
The reported error java.net.ConnectException: Connection refused is caused because Liferay cannot connect with the Elasticsearch server:
- Indeed, during the upgrade process, Liferay index functionality is switched to read-only, so there are no index operations in the Elasticsearch server and a full reindex is necessary once the upgrade process ends.
- Nevertheless, if the remote Elasticsearch server is not available, the Elasticsearch client module is not able to initialize correctly, causing the reported exception.
To avoid the issue you have two options:
Option 1: As a workaround, enable the Embedded Elasticsearch server during the upgrade process. This will eliminate the need to set up a separate Elasticsearch server during the upgrade testing. Follow the steps below:
- Before executing the upgrade, change the Elasticsearch client configuration in Liferay from remote to embedded mode.
- You can do it using configuration files following this article
- Execute the upgrade process
- Once the upgrade is finished, go to the system settings and configure the new remote Elasticsearch server for the new Liferay version
- Execute a full reindex
Option 2: Ensure that your Liferay server always has a remote Elasticsearch server configured and running, even if the upgrade process won't use it. However, consider the following important notes:
- When upgrading to a new Liferay version with a different Elasticsearch version requirement, always install the new Elasticsearch server and configure Liferay to use it before starting the upgrade.
- If you have cloned your Liferay environment for upgrade testing purposes, reconfigure Liferay to point to a different Elasticsearch server before executing the upgrade.
To modify the Liferay Elasticsearch configuration using config files before launching the server, refer to the official documentation: Liferay Elasticsearch Configuration.
Additional Information