Where can I find the reference for the spring-data-elasticsearch configuration properties?
Asked Answered
L

2

11

Across the web, I can see that spring-data-elasticsearch has some configuration properties that you can define in your application.properties, such as:

spring.data.elasticsearch.repositories.enabled=true
spring.data.elasticsearch.cluster-nodes=localhost:9300
spring.data.elasticsearch.cluster-name=elasticsearch

elasticsearch.index.name=my_index
elasticsearch.user.type=user

However, in IntelliJ, I can see that, for example:

spring.data.elasticsearch.cluster-nodes=localhost:9300
spring.data.elasticsearch.cluster-name=elasticsearch

... are actually now deprecated. However, I can't seem to find anything in the spring-data-elasticsearch documentations that either lists what the available properies are, or, what the deprecated ones should be replaced with instead.

Any help would be welcome. Thanks in advance!

Levelheaded answered 10/4, 2021 at 2:8 Comment(1)
This may help.Unnamed
O
9

Those properties are from spring-boot-starter-data-elasticsearch, not from spring-data-elasticsearch.

As @code_mechanic suggested, in Spring Boot Reference Documentation > Common Application properties > Data you will find the properties available for the current version of Spring Boot. Here some of the properties related to Elasticsearch:

Key Default Value Description
spring.data.elasticsearch.client.reactive.connection-timeout Connection timeout.
spring.data.elasticsearch.client.reactive.endpoints Comma-separated list of the Elasticsearch endpoints to connect to.
spring.data.elasticsearch.client.reactive.max-in-memory-size Limit on the number of bytes that can be buffered whenever the input stream needs to be aggregated.
spring.data.elasticsearch.client.reactive.password Credentials password.
spring.data.elasticsearch.client.reactive.socket-timeout Read and Write Socket timeout.
spring.data.elasticsearch.client.reactive.use-ssl false Whether the client should use SSL to connect to the endpoints.
spring.data.elasticsearch.client.reactive.username Credentials username.
spring.data.elasticsearch.repositories.enabled true Whether to enable Elasticsearch repositories.
spring.elasticsearch.rest.connection-timeout 1s Connection timeout.
spring.elasticsearch.rest.password Credentials password.
spring.elasticsearch.rest.read-timeout 30s Read timeout.
spring.elasticsearch.rest.uris [http://localhost:9200] Comma-separated list of the Elasticsearch instances to use.
spring.elasticsearch.rest.username Credentials username.

The reference documentation of previous versions of Spring Boot can be found in https://spring.io/projects/spring-boot#learn.

You might also be interested in Spring Boot Docs > Spring Boot Features > Working With Nosql Technologies > Elasticsearch, which describes how to connect using REST clients and reactive REST clients, the dependencies you need and the configuration properties.

Orphanage answered 10/4, 2021 at 4:0 Comment(0)
P
2

According to the Spring docs for Spring Data Elasticsearch :

The TransportClient is deprecated as of Elasticsearch 7 and will be removed in Elasticsearch 8. Spring Data Elasticsearch will support the TransportClient as long as it is available in the used Elasticsearch version but has deprecated the classes using it since version 4.0

Note: This would mean that Spring team would also deprecate the legacy properties supported for Elasticsearch 7.

Now, Spring team recommends the developers to use RestHighLevelClient which is now the default client of Elasticsearch. It is a direct replacement for the TransportClient as it accepts and returns the same request/response objects.

Code to demonstrate given below :

@Configuration
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {

       ClientConfiguration clientConfiguration = ClientConfiguration.builder()  
            .connectedTo("localhost:9300")
            .build();

        return RestClients.create(clientConfiguration).rest();                         
    }
}

The above configuration needs to be created by overriding the default bean. Moreover, you don't need to provide cluster name explicitly. It will automatically find it.

Read above linked documentation for reference as it has all the necessary information.

Padding answered 10/4, 2021 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.