0

I have the following elastic-search container configuration in my test case

    @Container
    public static  GenericContainer container = new GenericContainer<>("elasticsearch:7.7.0")
        .withExposedPorts(9200,9300).withEnv("discovery.type","single-node")
        .withNetwork(Network.newNetwork())
        .withNetworkAliases("someNetwork");

In a @BeforeAll annotated method I elasticsearch url property like this

System.setProperty("spring.data.elasticsearch.cluster-nodes", container.getContainerIpAddress() + ":" + container.getMappedPort(9300));

From power shell when I check the running containers (during the test case debug pause), I find something like this under ports column : 0.0.0.0:32844->9200/tcp, 0.0.0.0:32843->9300/tcp When I print container.getContainerIpAddress() + ":" + container.getMappedPort(9300), I get the same port mapped to 9300 in the container ports column, in this case localhost:32843, for sure the port is random and get changed in every new run.

when the code `conf = repo.save(conf); run, I get the following exception:

Caused by: org.apache.http.ProtocolException: Not a valid protocol version: This is not an HTTP port at org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:209) at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:245) at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114) at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: org.apache.http.ParseException: Not a valid protocol version: This is not an HTTP port at org.apache.http.message.BasicLineParser.parseProtocolVersion(BasicLineParser.java:148) at org.apache.http.message.BasicLineParser.parseStatusLine(BasicLineParser.java:366) at org.apache.http.impl.nio.codecs.DefaultHttpResponseParser.createMessage(DefaultHttpResponseParser.java:112) at org.apache.http.impl.nio.codecs.DefaultHttpResponseParser.createMessage(DefaultHttpResponseParser.java:50) at org.apache.http.impl.nio.codecs.AbstractMessageParser.parseHeadLine(AbstractMessageParser.java:156) at org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:207) ... 11 more

`

Shady Ragab
  • 705
  • 10
  • 26

1 Answers1

6

You are using a REST client to access Elasticsearch on port 9300. This is the port for the TransportClient. Wit a REST client you need to target port 9200.

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
  • I get a timeout exception:org.springframework.dao.DataAccessResourceFailureException: 5,000 milliseconds timeout on connection http-outgoing-1 [ACTIVE]; nested exception is java.lang.RuntimeException: 5,000 milliseconds timeout on connection http-outgoing-1 [ACTIVE] – Shady Ragab May 26 '20 at 20:25
  • Thnx..I have increased both socketTimeout and connectTimeout to 10 seconds...It's a silly not realistic value, but it's OK for my windows dev machine. – Shady Ragab May 26 '20 at 20:34
  • I'm creating highLevelRestClient using both the ports and sometimes RestClient works and sometimes it fails with the same error. I think I should not use 9300. `RestHighLevelClient highLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost[] { new HttpHost("localhost", 9200), new HttpHost("localhost", 9300) }));` – Vishal Patel May 29 '20 at 13:26
  • @VishalPatel 9200 is for http REST and 9300 for the native transport protocol. If you configure both for the restclient, it will choose one of both and fail when it gets the 9300 – P.J.Meisch May 29 '20 at 14:31