RestHighLevelClient parameter [include_type_name] with Elastic 8.5.1 - spring-boot

iam trying to run spring boot application with RestHighLevelClient 7.17.4 in compatibility mod with elastic 8.5.1 by fallowing guide. When application try to call get, i've got the fallowing error:
Elasticsearch exception [type=illegal_argument_exception, reason=request [/*] contains unrecognized parameter: [include_type_name]]
My configuration of RestHighLevelClient in compatibility mod:
#Value("${hs360.services.watchlist.mgmt.elasticsearch.host}")
private String elsHost;
#Value("${hs360.services.watchlist.mgmt.elasticsearch.port}")
private int elsRestPort;
#Bean(destroyMethod = "close")
public RestHighLevelClient sourceClient() {
return new RestHighLevelClientBuilder(
RestClient.builder(new HttpHost(elsHost, elsRestPort)).setRequestConfigCallback(r -> r.setConnectTimeout(60000).setSocketTimeout(90000)).build()
).setApiCompatibilityMode(true).build();
}
and snippet, when application try to call get:
GetIndexResponse indexResponse = restHighLevelClient.indices().get(new GetIndexRequest().indices("*"), RequestOptions.DEFAULT);
From log of request i can obviously see, that request contains parameter include_type_name
org.elasticsearch.client.RestClient : request [GET http://hs360-ss-s
ource-master:9200/*?master_timeout=30s&include_type_name=true&ignore_unavailable=false&expand_wildcards=open&all
ow_no_indices=true&ignore_throttled=false] returned 1 warnings: [299 Elasticsearch-8.5.1-c1310c45fc534583afe2c1c
03046491efba2bba2 "[ignore_throttled] parameter is deprecated because frozen indices have been deprecated. Consi
der cold or frozen tiers in place of frozen indices."]
I know, that this parameter is deprecated, i though compatibility mod would handle this, but obviously, there is something else. I tried to search for solution, when i can remove parameter from request, but without success.
How could i remove that parameter from request or work around this problem?

You either need to upgrade to Spring Boot 3.0 which supports ES 8.5 or downgrade Elastic to whatever your Spring Boot version supports

Related

Classcastexception for CloudEventMessageConverter to AbstractMessageConverter

when using spring cloud stream latest version with cloud events spring sdk
Facing classcastexception in below scenario.
Message has contentType = application/*+avro.
SmartcompositeMessageConverter contains converter list like below -
CloudEventMessageConverter
AvroSchemaRegisteryClientMessageConverter
and some ootb converters.
While converting to message from producer..
SmartcompositeMessageConverter has this line of code for wildcard contentType
((AbstractMessageConverter) converter).getSupportedMimeTypes()
But CloudEventMessageConverter is not an instance of AbstractMessageConverter, hence it throws an exception.
Please guide what should be overridden in this case.
If I create a new CloudEventMessageConverter which extends AbstractMessageConverter, I cann't add headers as only method allowed to override is convertFromInternal which returns just the payload.

Unable to find "UpdateQueryBuilder" in springframework data 4

I am upgrading spring elasticsearch data from 3.x to 4.2.1. The support of UpdateQueryBuilder is removed from the latest version which earlier I used to construct UpdateQuery from UpdateRequest object of elasticsearch. For example:
return new UpdateQueryBuilder()
.withId(documentId)
.withClass(getDocumentClass())
.withUpdateRequest(updateRequest)
.build();
The new class UpdateQuery doesn't accept UpdateRequest object but only accepts Query. I would prefer to avoid UpdateRequest conversion to Query somehow.
Does anyone have suggestions on how to make UpdateQuery and UpdateRequest work together?
After the change from 3.2.x to 4.0 a year ago Spring Data Elasticsearch does not accept Elasticsearch classes as parameters to the API in order to constantly abstract away Elasticsearch implementation details from the SDE user.
From 4.0 on there is the nested UpdateQuery.Builder class on which you should be able to set all the parameters you did previously on the org.elasticsearch.action.update.UpdateRequest class.

Created RestHighLevelClient for Elasticsearch won't use SSL

I am trying to connect to an existing Elasticsearch instance. The instance is set up and working fine, which I can confirm by accessing it through the browser under https://localhost:9200. I am using Spring Data Elasticsearch version 4.1.2 and I am following the official instructions from https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.rest.
Unfortunately, when starting the application, the initial health checks of the elasticsearch instance fail, because the code is trying to use http instead of https:
o.s.w.r.f.client.ExchangeFunctions : [377e90b0] HTTP HEAD http://localhost:9200/
Therefore I added the ".usingSsl()" to the ClientConfiguration, but it does not seem to have any effect and I just don't understand why. The "funny" thing is, if I implement the reactive client as described here (https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.reactive), https suddenly works and the applications starts perfectly fine. However, I want to use the regular high level client.
Can you help me change the configuration in a way so that it finally makes use of https instead of http?
#Configuration
class ElasticsearchClientConfig: AbstractElasticsearchConfiguration() {
#Bean
override fun elasticsearchClient(): RestHighLevelClient {
val clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200")
.usingSsl()
.build();
return RestClients.create(clientConfiguration).rest();
}
}

ElasticsearchJestHealthIndicator : Health check failed when using Jest in spring boot

I'm using Jest at enter link description here in my spring boot application.
Then I created the client with the example code :
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("http://myhost:9200")
.multiThreaded(true)
JestClient client = factory.getObject();
Everything is fine. I can use this client to do all the queries I want. Happy till now.
Then the problem, when the application starts up, ElasticsearchJestHealthIndicator class is auto-initialized. But the problem is I don't know where to set the config that it will need, so it uses the default value as http://localhost:9200, which leads me to this problem:
WARN [on(2)-127.0.0.1] s.b.a.h.ElasticsearchJestHealthIndicator : Health check failed
io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://localhost:9200
at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:70)
at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:60)
Can someone show me how to properly config it , or turn it off ?
A quick search in the reference documentation shows that Spring Boot will configure for you a JestClient (you can just inject it anywhere you need), and that the following configuration properties apply:
spring.elasticsearch.jest.uris=http://search.example.com:9200
spring.elasticsearch.jest.read-timeout=10000
spring.elasticsearch.jest.username=user
spring.elasticsearch.jest.password=secret
See here for more on this.
The Jest client has been deprecated as well, since both Elasticsearch and Spring Data Elasticsearch provide official support for REST clients.
See https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-elasticsearch

How to configure Spring Boot with elasticsearch 5.2.1?

I am trying to connect my Spring Boot application to local elasticsearch 5.2.1 instance. When i use "org.springframework.boot:spring-boot-starter-data-elasticsearch" dependency, i face with "Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]". I think this is due to elasticsearch version is 2.4.4 in starter dependency. So to solve this error, i edit pom.xml properties by adding elasticsearch.version>5.2.1/elasticsearch.version> line. But this time i get
"java.lang.NoSuchMethodError: org.elasticsearch.client.transport.TransportClient.builder()"
To overcome this issue, i create custom config class like below:
#Configuration
public class ElasticsearchConfiguration {
#Bean
public Client client() throws UnknownHostException {
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
return client;
}
#Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(client());
}
}
This time i get apache.logging.log4j exceptions (check here) so i add necessary dependencies.
Finally i get below error and stucked there. Could anyone help me out with this?
nested exception is java.lang.NoClassDefFoundError:org/elasticsearch/action/count/CountRequestBuilder
The github page of spring-data-elasticsearch shows that it currently supports elasticsearch only up to version 2.4.0.
For now you have 3 options:
Wait and hope
checkout the pull request
checkout the dev branch 5.0.x-prep
You need to use Spring Boot 2. Check out my spring-boot-elasticsearch-5.x example.
You can use elasticsearch java api to create transport client instead of using spring-data-elasticsearch.
I tried the same and getting that error too for CountRequestBuilder, reason is that CountRequestBuilder class is deprecated and removed now from 5.x elastic search versions, that class is replaced by SearchRequestBuilder but unfortunately spring-data-elasticsearch don't provide this even in the latest release of its jar and that CountRequestBuilder is used in ElasticSearchTemplate.
I am also looking out for some solution. I will post if able to resolve.

Resources