# Localhost:9200: nodename nor servname provided, or not known

**URL:** <https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173>\
**Category:** Elasticsearch\
**Created:** [June 18, 2019, 3:04am UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173 "2019-06-18T03:04:46Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 18, 2019, 3:04am UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/1 "2019-06-18T03:04:46Z")

</div>

I am running elastic search version 6.4 locally and my dependency for the spring boot application is implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.4.0' . I am getting java.io.IOException: localhost:9200: nodename nor servname provided, or not known  
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:948)  
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227)  
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:272)  
.I tried localhost only also but still getting same problem. But when I am using same code but server elastic search I am getting having problem. Previously I am using elastic search transport. at that time there was no problem while connection but i upgrade to rest-high-level client ..I am facing problem ... Can some one help me.....

---

<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:** [June 18, 2019, 5:05am UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/2 "2019-06-18T05:05:32Z")

</div>

Please share your code and format it using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 18, 2019, 12:32pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/3 "2019-06-18T12:32:11Z")

</div>

This is my elastic configuration class:

```
@Bean(destroyMethod = "close")
    public RestHighLevelClient client() {

        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost(elasticHost)));
        return client;

    }

```

and in my service class I am trying to check index is already exist or not using

```
public boolean checkIfIndexExists(String indexName) throws IOException {
        Response response = client.getLowLevelClient().performRequest("HEAD", "/" + indexName);
        int statusCode = response.getStatusLine().getStatusCode();
        return (statusCode != 404);
    }

```

Where same code is working on the server but not in the local.. where in local I am using elastic 6.4.2 and maven also the same version.

---

<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:** [June 18, 2019, 1:34pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/4 "2019-06-18T13:34:11Z")

</div>

Can you print debug the content of `elasticHost`?

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 18, 2019, 2:09pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/5 "2019-06-18T14:09:21Z")

</div>

> [@sneup](#):
>
> elasticHost

Hi Dadoonet,  
My elasticHost is localhost:9200.. which I am reading from YML

---

<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:** [June 18, 2019, 2:11pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/6 "2019-06-18T14:11:40Z")

</div>

Can you replace it with an IP address like `127.0.0.1`?

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 18, 2019, 2:20pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/7 "2019-06-18T14:20:03Z")

</div>

> [@dadoonet](#):
>
> 127.0.0.1

Yes I tried but still having same problem. previously when i use elastic transport (with transport code) it was working perfectly on the localhost:9200 port. But after changing with the above configuration for highlevel client I am facing problem on my local machine.

---

<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:** [June 18, 2019, 4:27pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/8 "2019-06-18T16:27:36Z")

</div>

Could you try this?

> <https://github.com/dadoonet/legacy-search/blob/01-direct/src/main/java/fr/pilato/demo/legacysearch/dao/ElasticsearchDao.java#L49>

I mean manually set the IP like:

```auto
new RestHighLevelClient(RestClient.builder(HttpHost.create("http://127.0.0.1:9200")));

```

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 18, 2019, 5:33pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/9 "2019-06-18T17:33:02Z")

</div>

Thank you for the response dodoonet. Still having the same problem. .. when I use the hardcoded value(HttpHost.create("[http://127.0.0.1:9200](http://127.0.0.1:9200)")) in configuration file getting this image error.

 ![24%20PM](https://us1.discourse-cdn.com/elastic/original/3X/4/9/49ca55321f3834911b7aee697bf7a9e13ea45138.jpeg)

But when I use restclient in the inline (as you suggested) I am able to connect to the localhost. that means it is successfully why ? But for the server connection I dont have to do that..

```
client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://127.0.0.1:9200")));
        Response response = client.getLowLevelClient().performRequest("HEAD", "/" + indexName);
        int statusCode = response.getStatusLine().getStatusCode();
```

---

<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:** [June 20, 2019, 1:25pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/10 "2019-06-20T13:25:50Z")

</div>

So when you read from a config file it does not work right?

---

<div class="post-metadata">

**Author:** ![pokaleshrey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pokaleshrey/32/48680_2.png) [@pokaleshrey](https://discuss.elastic.co/u/pokaleshrey)\
**Post date:** [June 20, 2019, 1:37pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/11 "2019-06-20T13:37:16Z")

</div>

Did you try using below while creating RestClient:

`new HttpHost("localhost", 9200, "http")`

instead of

`HttpHost.create("http://127.0.0.1:9200")`

This works for us in local and on server and everywhere.

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 21, 2019, 4:09pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/12 "2019-06-21T16:09:21Z")

</div>

Actually No @dadoonet , If that happens it should not get the value in the above screenshot. You see in the above image the value is coming from the config file.

---

<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:** [June 21, 2019, 5:10pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/13 "2019-06-21T17:10:09Z")

</div>

But you said you are successful in one case. Which one is it?

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 21, 2019, 8:14pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/14 "2019-06-21T20:14:58Z")

</div>

I said When I create a bean and @autowired that bean is not working for localhost/9200. But the same code with server elastic(AWS) search is working. And for the localhost if I write the code inside the same method like this

`client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://127.0.0.1:9200")));`

it is working. I am confuse why the localhost is not working while autowire the configuration class.

my configuration class is

@Configuration  
public class ElasticsearchConfig {

```
@Bean(destroyMethod = "close")
public RestHighLevelClient client() {

    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(new HttpHost("http://127.0.0.1:9200")));
    return client;

}

```

}

---

<div class="post-metadata">

**Author:** ![sneup](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sneup/32/48265_2.png) [@sneup](https://discuss.elastic.co/u/sneup)\
**Post date:** [June 21, 2019, 8:23pm UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/15 "2019-06-21T20:23:40Z")

</div>

> [@pokaleshrey](#):
>
> new HttpHost("localhost", 9200, "http")

Thank you This way its working for localhost also!!!!

---

<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:** [June 22, 2019, 2:56am UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/16 "2019-06-22T02:56:36Z")

</div>

So is it solved?

---

<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:** [July 20, 2019, 2:56am UTC](https://discuss.elastic.co/t/localhost-nodename-nor-servname-provided-or-not-known/186173/17 "2019-07-20T02:56:41Z")

</div>

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