Search in sources :

Example 1 with ElasticsearchRestTemplate

use of org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate in project spring-data-elasticsearch by spring-projects.

the class AbstractElasticsearchConfiguration method elasticsearchOperations.

/**
 * Creates {@link ElasticsearchOperations}.
 *
 * @return never {@literal null}.
 */
@Bean(name = { "elasticsearchOperations", "elasticsearchTemplate" })
public ElasticsearchOperations elasticsearchOperations(ElasticsearchConverter elasticsearchConverter, RestHighLevelClient elasticsearchClient) {
    ElasticsearchRestTemplate template = new ElasticsearchRestTemplate(elasticsearchClient, elasticsearchConverter);
    template.setRefreshPolicy(refreshPolicy());
    return template;
}
Also used : ElasticsearchRestTemplate(org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate) Bean(org.springframework.context.annotation.Bean)

Example 2 with ElasticsearchRestTemplate

use of org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate in project spring-data-elasticsearch by spring-projects.

the class ElasticsearchRestTemplateConfiguration method elasticsearchOperations.

@Override
public ElasticsearchOperations elasticsearchOperations(ElasticsearchConverter elasticsearchConverter, RestHighLevelClient elasticsearchClient) {
    ElasticsearchRestTemplate template = new ElasticsearchRestTemplate(elasticsearchClient, elasticsearchConverter) {

        @Override
        public <T> T execute(ClientCallback<T> callback) {
            try {
                return super.execute(callback);
            } catch (DataAccessResourceFailureException e) {
                try {
                    Thread.sleep(1_000);
                } catch (InterruptedException ignored) {
                }
                return super.execute(callback);
            }
        }
    };
    template.setRefreshPolicy(refreshPolicy());
    return template;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) ElasticsearchRestTemplate(org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate)

Aggregations

ElasticsearchRestTemplate (org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate)2 Bean (org.springframework.context.annotation.Bean)1 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)1