diff --git a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/main/java/org/nuxeo/elasticsearch/client/ESRestClientFactory.java b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/main/java/org/nuxeo/elasticsearch/client/ESRestClientFactory.java
index 220110810fa..d84611d24cd 100644
--- a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/main/java/org/nuxeo/elasticsearch/client/ESRestClientFactory.java
+++ b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/main/java/org/nuxeo/elasticsearch/client/ESRestClientFactory.java
@@ -27,6 +27,7 @@ import java.security.KeyStore;
 
 import javax.net.ssl.SSLContext;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -40,6 +41,8 @@ import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestClientBuilder;
 import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.common.transport.TransportAddress;
+import org.elasticsearch.http.HttpServerTransport;
 import org.nuxeo.ecm.core.api.NuxeoException;
 import org.nuxeo.elasticsearch.api.ESClient;
 import org.nuxeo.elasticsearch.api.ESClientFactory;
@@ -102,18 +105,25 @@ public class ESRestClientFactory implements ESClientFactory {
     @Override
     public ESClient create(ElasticSearchEmbeddedNode node, ElasticSearchClientConfig config) {
         if (node != null) {
-            return createLocalRestClient(node.getConfig());
+            return createLocalRestClient(node);
         }
         return createRestClient(config);
     }
 
-    protected ESClient createLocalRestClient(ElasticSearchEmbeddedServerConfig serverConfig) {
-        if (!serverConfig.httpEnabled()) {
+    protected ESClient createLocalRestClient(ElasticSearchEmbeddedNode node) {
+        if (!node.getConfig().httpEnabled()) {
             throw new IllegalArgumentException(
                     "Embedded configuration has no HTTP port enable, use TransportClient instead of Rest");
         }
-        RestClientBuilder lowLevelRestClientBuilder = RestClient.builder(
-                new HttpHost("localhost", Integer.parseInt(serverConfig.getHttpPort())));
+
+        HttpServerTransport http = node.getNode().injector().getInstance(HttpServerTransport.class);
+        TransportAddress[] addresses = http.boundAddress().boundAddresses();
+        if (ArrayUtils.isEmpty(addresses)) {
+            throw new IllegalStateException("Embedded did not bind any address");
+        }
+
+        int port = addresses[0].getPort();
+        RestClientBuilder lowLevelRestClientBuilder = RestClient.builder(new HttpHost("localhost", port));
         RestHighLevelClient client = new RestHighLevelClient(lowLevelRestClientBuilder); // NOSONAR (factory)
         // checkConnection(client);
         return new ESRestClient(client.getLowLevelClient(), client);
diff --git a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestESRestClient.java b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestESRestClient.java
index f525bffd219..a269cacb314 100644
--- a/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestESRestClient.java
+++ b/nuxeo-features/nuxeo-elasticsearch/nuxeo-elasticsearch-core/src/test/java/org/nuxeo/elasticsearch/test/TestESRestClient.java
@@ -43,10 +43,7 @@ public class TestESRestClient extends TestESClient {
 
     @Override
     public ESClient createClient(ElasticSearchEmbeddedNode embeddedNode) {
-        ElasticSearchEmbeddedServerConfig config = new ElasticSearchEmbeddedServerConfig();
-        config.setHttpEnabled(true);
-        ElasticSearchEmbeddedNode node = new ElasticSearchEmbeddedNode(config);
-        return factory.create(node, new ElasticSearchClientConfig());
+        return factory.create(embeddedNode, new ElasticSearchClientConfig());
     }
 
     @Test(expected = IllegalArgumentException.class)
