Skip to content

Commit acd7990

Browse files
authored
Default Refresh policy for ReactiveElasticsearchTemplate.
Original Pull Request #2124 Closes #2110
1 parent b10eb75 commit acd7990

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Diff for: src/main/asciidoc/reference/elasticsearch-migration-guide-4.3-4.4.adoc

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ Connections to Elasticsearch must be made using either the imperative `Elasticse
2828
In 4.3 two classes (`ElasticsearchAggregations` and `ElasticsearchAggregation`) had been moved to the `org.springframework.data.elasticsearch.core.clients.elasticsearch7` package in preparation for the integration of the new Elasticsearch client.
2929
The were moved back to the `org.springframework.data.elasticsearch.core` package as we keep the classes use the old Elasticsearch client where they were.
3030

31+
=== Behaviour change
32+
33+
The `ReactiveElasticsearchTemplate`, when created directly or by Spring Boot configuration had a default refresh policy of IMMEDIATE.
34+
This could cause performance issues on heavy indexing and was different than the default behaviour of Elasticsearch.
35+
This has been changed to that now the default refresh policy is NONE.
36+
When the
37+
`ReactiveElasticsearchTemplate` was provided by using the configuration like described in <<elasticsearch.clients.reactive>> the default refresh policy already was set to NONE.
38+
3139
[[elasticsearch-migration-guide-4.3-4.4.new-clients]]
3240
== New Elasticsearch client
3341

Diff for: src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract public class AbstractReactiveElasticsearchTemplate
7373
protected final SimpleElasticsearchMappingContext mappingContext;
7474
protected final EntityOperations entityOperations;
7575

76-
protected @Nullable RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
76+
protected @Nullable RefreshPolicy refreshPolicy = RefreshPolicy.NONE;
7777
protected RoutingResolver routingResolver;
7878

7979
protected @Nullable ReactiveEntityCallbacks entityCallbacks;

Diff for: src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateUnitTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void insertShouldUseDefaultRefreshPolicy() {
8585
.as(StepVerifier::create) //
8686
.verifyComplete();
8787

88-
assertThat(captor.getValue().getRefreshPolicy()).isEqualTo(WriteRequest.RefreshPolicy.IMMEDIATE);
88+
assertThat(captor.getValue().getRefreshPolicy()).isEqualTo(WriteRequest.RefreshPolicy.NONE);
8989
}
9090

9191
@Test // DATAES-504
@@ -170,7 +170,7 @@ public void deleteShouldUseDefaultRefreshPolicy() {
170170
.as(StepVerifier::create) //
171171
.verifyComplete();
172172

173-
assertThat(captor.getValue().getRefreshPolicy()).isEqualTo(WriteRequest.RefreshPolicy.IMMEDIATE);
173+
assertThat(captor.getValue().getRefreshPolicy()).isEqualTo(WriteRequest.RefreshPolicy.NONE);
174174
}
175175

176176
@Test // DATAES-504
@@ -198,7 +198,7 @@ public void deleteByShouldUseDefaultRefreshPolicy() {
198198
.as(StepVerifier::create) //
199199
.verifyComplete();
200200

201-
assertThat(captor.getValue().isRefresh()).isTrue();
201+
assertThat(captor.getValue().isRefresh()).isFalse();
202202
}
203203

204204
@Test // DATAES-504
@@ -207,13 +207,13 @@ public void deleteByShouldApplyRefreshPolicy() {
207207
ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
208208
when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
209209

210-
template.setRefreshPolicy(RefreshPolicy.NONE);
210+
template.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
211211

212212
template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index) //
213213
.as(StepVerifier::create) //
214214
.verifyComplete();
215215

216-
assertThat(captor.getValue().isRefresh()).isFalse();
216+
assertThat(captor.getValue().isRefresh()).isTrue();
217217
}
218218

219219
@Test // DATAES-504

0 commit comments

Comments
 (0)