# Elasticsearch - Low Level Rest Client Initialisation throwing exception

**URL:** <https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046>\
**Category:** Elasticsearch\
**Created:** [February 12, 2019, 2:18pm UTC](https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046 "2019-02-12T14:18:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [February 12, 2019, 2:18pm UTC](https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046/1 "2019-02-12T14:18:44Z")

</div>

Hi,  
I am working on implementing Low Level Rest Client.  
I am facing issues with Initialising RestClient.  
The dependency in pom.xml is :

```
  <dependency>
		    <groupId>org.elasticsearch.client</groupId>
		    <artifactId>elasticsearch-rest-client</artifactId>
		    <version>6.4.3</version>
		</dependency>

```

Initialisation of RestClient is :

```
RestClient restClient =RestClient.builder( new HttpHost("10.50.1.100", 9998, "http")).build();

```

This particular line of code is throwing an ClassNotFoundException  
To be specific -

SEVERE: Servlet.service() for servlet [elasticsearch] in context with path [/ElasticSearch] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/conn/util/PublicSuffixMatcherLoader] with root cause  
java.lang.ClassNotFoundException: org.apache.http.conn.util.PublicSuffixMatcherLoader  
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)  
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)  
at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:640)  
at org.elasticsearch.client.RestClientBuilder$2.run(RestClientBuilder.java:230)  
at org.elasticsearch.client.RestClientBuilder$2.run(RestClientBuilder.java:227)  
at java.security.AccessController.doPrivileged(Native Method)  
at org.elasticsearch.client.RestClientBuilder.createHttpClient(RestClientBuilder.java:227)  
at org.elasticsearch.client.RestClientBuilder.access$000(RestClientBuilder.java:42)  
at org.elasticsearch.client.RestClientBuilder$1.run(RestClientBuilder.java:198)  
at org.elasticsearch.client.RestClientBuilder$1.run(RestClientBuilder.java:195)  
at java.security.AccessController.doPrivileged(Native Method)  
at org.elasticsearch.client.RestClientBuilder.build(RestClientBuilder.java:195)

I am sure I am missing something very basic here.  
Where am I going wrong?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 12, 2019, 2:42pm UTC](https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046/2 "2019-02-12T14:42:09Z")

</div>

Sounds like you are running your code in a WebApp.  
May be you have some dependencies which are clashing with the ones used by the Rest Client. (Http Client).

---

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [February 13, 2019, 11:27am UTC](https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046/3 "2019-02-13T11:27:08Z")

</div>

Thanks for your response  
As I see, I have the following http Client dependency on my application

```
<!-- Apache Http client -->
<dependency>
	<groupId>org.apache.httpcomponents</groupId>
	<artifactId>httpclient</artifactId>
	<version>4.3.5</version>
</dependency>
<dependency>
	<groupId>org.apache.httpcomponents</groupId>
	<artifactId>httpcore</artifactId>
	<version>4.3.2</version>
</dependency>

```

After removing these dependencies, my code started to work fine.

Although I have one doubt, Is it a safe practice to initialise Rest Client each time I do some operation like create index or search request and close it right after its usage? Or is it okay to initialise Rest Client once at the server start up ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2019, 11:55am UTC](https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046/4 "2019-02-13T11:55:37Z")

</div>

I'd use a singleton and initialize it once per application.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 13, 2019, 11:55am UTC](https://discuss.elastic.co/t/elasticsearch-low-level-rest-client-initialisation-throwing-exception/168046/5 "2019-03-13T11:55:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
