<p>I have an application which consists of a backend (spring boot) and a search engine (elasticsearch). After I deployed it into OCP, Initially I tested the connection between the two using the command &quot;curl&quot; to elasticsearch service <code>(https://service-name.namespace.svc.cluster.local:9200)</code> from backend pod and it worked. Here's the picture:
<a href="https://i.stack.imgur.com/QEbfY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QEbfY.png" alt="enter image description here" /></a></p>
<p>However, when I try to access elasticsearch from within the deployed backend application, an error message appears as below:
<a href="https://i.stack.imgur.com/heWjN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/heWjN.png" alt="enter image description here" /></a></p>
<p>And here are my configuration in Spring Boot to connect with Elasticsearch that I did:</p>
<pre><code>package com.siolbca.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

@Configuration
@EnableElasticsearchRepositories(basePackages = &quot;com.siolbca.repository&quot;)
@ComponentScan(basePackages = &quot;com.siolbca.services&quot;)
public class Config {
    @Bean
    public RestHighLevelClient client() {
        ClientConfiguration clientConfiguration 
            = ClientConfiguration.builder()
                .connectedTo(&quot;https://elasticsearch-siol-es-http.siolbca-dev.svc.cluster.local:9200&quot;)
                .usingSsl()
                .withBasicAuth(&quot;elastic&quot;,&quot;G0D1g6TurJ79pcxr1065pU0U&quot;)
                .build();

        return RestClients.create(clientConfiguration).rest();
    }

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() {
        return new ElasticsearchRestTemplate(client());
    }

}
</code></pre>
<p>Some of the things I have done are:</p>
<ol>
<li>Use the elasticsearch service IP address directly in the backend configuration</li>
</ol>
<blockquote>
<p>https://elasticsearch-service-ipaddress:9200</p>
</blockquote>
<ol start="2">
<li>Expose a route from elasticsearch service and put it in the backend configuration</li>
</ol>
<blockquote>
<p>https://elasticsearch-route:443</p>
</blockquote>
<ol start="3">
<li>Change the service url into</li>
</ol>
<blockquote>
<p><a href="https://service-name.namespace.svc:9200" rel="nofollow noreferrer">https://service-name.namespace.svc:9200</a></p>
</blockquote>
<p>Does anyone know why my backend app can't communicate with the elasticsearch service even though the two pods are able to connect? Any answer would be very helpful. Thank you.</p>
<hr />
<p><strong>EDIT</strong></p>
<p>Here's my pom.xml</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.4.3&lt;/version&gt;
        &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
    &lt;/parent&gt;
    &lt;groupId&gt;com.siolbca&lt;/groupId&gt;
    &lt;artifactId&gt;siolbca&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;name&gt;siolbca&lt;/name&gt;
    &lt;description&gt;Backend project for SIOLBCA&lt;/description&gt;
    &lt;properties&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
            &lt;artifactId&gt;spring-data-elasticsearch&lt;/artifactId&gt;
            &lt;version&gt;4.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

&lt;/project&gt;
</code></pre>

<p>I think the elasticsearch builder <code>.connectedTo</code> method requires the format <code>host:port</code>,  i.e. without the protocol.
So try:</p>
<pre><code>.connectedTo(&quot;elasticsearch-siol-es-http.siolbca-dev.svc.cluster.local:9200&quot;)
</code></pre>
