Hello, I am developing a project using postgresql elasticsearch and spring boot.
When i run my code, i get an error like below.
Caused by: org.springframework.dao.DataAccessResourceFailureException: method [PUT], host [http://localhost:9200], URI [/agenda], status line [HTTP/1.1 406 Not Acceptable]
{"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported","status":406}
at org.springframework.data.elasticsearch.client.elc.ElasticsearchExceptionTranslator.translateExceptionIfPossible(ElasticsearchExceptionTranslator.java:110) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.client.elc.ElasticsearchExceptionTranslator.translateException(ElasticsearchExceptionTranslator.java:64) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.client.elc.ChildTemplate.execute(ChildTemplate.java:73) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.client.elc.IndicesTemplate.doCreate(IndicesTemplate.java:145) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.client.elc.IndicesTemplate.createWithMapping(IndicesTemplate.java:135) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.<init>(SimpleElasticsearchRepository.java:86) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:208) ~[spring-beans-6.1.6.jar:6.1.6]
... 57 common frames omitted
Caused by: java.lang.RuntimeException: method [PUT], host [http://localhost:9200], URI [/agenda], status line [HTTP/1.1 406 Not Acceptable]
{"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported","status":406}
at org.springframework.data.elasticsearch.client.elc.ElasticsearchExceptionTranslator.translateException(ElasticsearchExceptionTranslator.java:63) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
... 65 common frames omitted
Caused by: org.elasticsearch.client.ResponseException: method [PUT], host [http://localhost:9200], URI [/agenda], status line [HTTP/1.1 406 Not Acceptable]
{"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported","status":406}
at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:347) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:313) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
at co.elastic.clients.transport.rest_client.RestClientHttpClient.performRequest(RestClientHttpClient.java:91) ~[elasticsearch-java-8.10.4.jar:na]
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:137) ~[elasticsearch-java-8.10.4.jar:na]
at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.create(ElasticsearchIndicesClient.java:266) ~[elasticsearch-java-8.10.4.jar:na]
at org.springframework.data.elasticsearch.client.elc.IndicesTemplate.lambda$doCreate$0(IndicesTemplate.java:145) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.client.elc.ChildTemplate.execute(ChildTemplate.java:71) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
... 64 common frames omitted
this is my ElasticConfig class.
Spring Boot version: 3.2.5
Spring-Data-Elasticsearch Version: 5.2.5
Elasticsearch-rest-high-level-client Version: 7.17.21
Below code is my first try code.
@Configuration
@EnableElasticsearchRepositories(basePackages = "*")
public class ElasticSearchConfiguration {
@Bean(destroyMethod = "close")
public RestHighLevelClient restClient() {
String host = "127.0.0.1";
int port = 9200;
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
RestClientBuilder builder = RestClient
.builder(new HttpHost(host, port))
.setDefaultHeaders(new Header[]{
new BasicHeader("Content-type", "application/json")
})
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
RestHighLevelClient client = new RestHighLevelClient(builder);
return client;
}
}
Below code is my second try code.
@Configuration
@EnableElasticsearchRepositories(basePackages = "*")
public class ElasticSearchConfiguration extends ElasticsearchConfiguration {
@Override
public ClientConfiguration clientConfiguration() {
Supplier<HttpHeaders> headersSupplier = () -> {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
return headers;
};
return ClientConfiguration.builder()
.connectedTo("localhost:9200")
.withHeaders(headersSupplier)
.build();
}
}
Caused by: org.springframework.data.elasticsearch.UncategorizedElasticsearchException: [es/indices.create] failed: [content_type_header_exception] java.lang.IllegalArgumentException: only one Content-Type header should be provided
And my configuration is like below code.
@Configuration
@EnableElasticsearchRepositories(basePackages = "*")
public class ElasticSearchConfiguration extends ElasticsearchConfiguration {
@Override
public ClientConfiguration clientConfiguration() {
Supplier<HttpHeaders> headersSupplier = () -> {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
return headers;
};
return ClientConfiguration.builder()
.connectedTo("localhost:9200")
.withHeaders(headersSupplier)
.build();
}
}
Firstly, i deleted my all docker containers and i am running try elasticsearch offical guide.
And my elasticsearch running on 0.0.0.0 host and 5601 port
After than I change my config class like below.
@Configuration
@EnableElasticsearchRepositories(basePackages = "*")
public class ElasticSearchConfiguration extends ElasticsearchConfiguration {
@Override
public ClientConfiguration clientConfiguration() {
Supplier<HttpHeaders> headersSupplier = () -> {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
return headers;
};
return ClientConfiguration.builder()
.connectedTo("http://0.0.0.0:5601/")
.withHeaders(headersSupplier)
.build();
}
But now this error,
Caused by: java.io.IOException: http://0.0.0.0:5601/: nodename nor servname provided, or not known
at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:935) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:300) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
at co.elastic.clients.transport.rest_client.RestClientHttpClient.performRequest(RestClientHttpClient.java:91) ~[elasticsearch-java-8.10.4.jar:na]
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:137) ~[elasticsearch-java-8.10.4.jar:na]
at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.exists(ElasticsearchIndicesClient.java:655) ~[elasticsearch-java-8.10.4.jar:na]
at org.springframework.data.elasticsearch.client.elc.IndicesTemplate.lambda$doExists$2(IndicesTemplate.java:177) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
at org.springframework.data.elasticsearch.client.elc.ChildTemplate.execute(ChildTemplate.java:71) ~[spring-data-elasticsearch-5.2.5.jar:5.2.5]
... 64 common frames omitted
Caused by: java.net.UnknownHostException: http://0.0.0.0:5601/: nodename nor servname provided, or not known
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52) ~[na:na]
at java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1211) ~[na:na]
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1828) ~[na:na]
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1139) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1818) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1688) ~[na:na]
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) ~[httpclient-4.5.13.jar:4.5.13]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:666) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:637) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:472) ~[httpcore-nio-4.4.16.jar:4.4.16]
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:280) ~[httpcore-nio-4.4.16.jar:4.4.16]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:295) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:381) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:130) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.execute(CloseableHttpAsyncClientBase.java:116) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:138) ~[httpasyncclient-4.1.5.jar:4.1.5]
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:296) ~[elasticsearch-rest-client-8.10.4.jar:8.10.4]
... 70 common frames omitted
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.