SocketException on _bulk request working in curl but not in restTemplate


I have problems with _bulk request throwing Connection reset by peer: socket write error; nested exception is

I've read and know about bulk size and etc... So that's not an issue, because the same exact request works with curl or intelij http client:

PUT {{elastic-search-url}}/_bulk
Authorization: Basic {{username}} {{password}}
Accept: application/json
Content-Type: application/x-ndjson

< input.txt

However if I try using spring boot restTemplate I get the error Connection reset by peer:

HttpEntity<String> requestEntity = new HttpEntity<>(stringBuilder.toString(), getHeaderEntity());
restTemplate.put("ELKurl/_bulk", requestEntity, Object.class);

Header entity have all required authorization and accepts:

headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));

SSL for restTemplate is disabled:

private CloseableHttpClient createHttpClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
        return HttpClients
                .setSSLHostnameVerifier(new NoopHostnameVerifier())
private SSLContext createSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
        return new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (arg0, arg1) -> true).build();

I don't know what else can cause problems? I also checked logs on ELK server side, but nothing can be found there.
How can curl work and spring boot not? :slight_smile:

ELK version 7.17.5

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