title: Elk connection failure
body: <p>We are working to secure the connection between an api in Spring boot and an ELK.</p>
  <p>In the connection we have added the following code:</p>
  <pre><code>public class ElasticClientProviderService {
  
  private RestHighLevelClient client;
  private RestHighLevelClient clientBigTimeout;
  public ElasticClientProviderService(
          @Value(&quot;${elasticsearch.server.host}&quot;) String host,
          @Value(&quot;${elasticsearch.server.port}&quot;) int port,
          @Value(&quot;${elasticsearch.server.user}&quot;) String user,
          @Value(&quot;${elasticsearch.server.pass}&quot;) String pass,
          @Value(&quot;${elasticsearch.server.method}&quot;) String method) {
      final CredentialsProvider credentialsProvider =
              new BasicCredentialsProvider();
          credentialsProvider.setCredentials(AuthScope.ANY,
              new UsernamePasswordCredentials(&quot;user&quot;, &quot;pass&quot;));
      if (client != null &amp;&amp; host != null &amp;&amp; method != null &amp;&amp; user != null ) {
          client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port))
                  .setHttpClientConfigCallback(httpClientBuilder -&gt; httpClientBuilder.
                          setDefaultCredentialsProvider(credentialsProvider)));
      }
      if (clientBigTimeout == null &amp;&amp; host != null &amp;&amp; user != null &amp;&amp; pass !=null &amp;&amp; method != null) {
          clientBigTimeout = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, method))
                  .setRequestConfigCallback(requestConfigBuilder -&gt; requestConfigBuilder.setSocketTimeout(5 * 60 * 1000)));
      }
  }
  public RestHighLevelClient getClient() {
      return client;
  }
  
  public RestHighLevelClient getClientBigTimeout() {
      return clientBigTimeout;
  }
  </code></pre>
  <p>The logs record the following faults:</p>
  <pre><code>ERROR [app,,,] 1 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : 
     Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception 
     [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
     java.lang.NullPointerException: null
   at com.app.onehr.user.infrastructure.ElasticUserRepository.search(ElasticUserRepository.java:87) ~ 
     [classes!/:0.6.0-SNAPSHOT]…”
  </code></pre>