Skip to content

Commit a5d0520

Browse files
committed
1 parent 46695d7 commit a5d0520

9 files changed

+62
-39
lines changed

src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,17 @@ public Flux<? extends AggregationContainer<?>> aggregate(Query query, Class<?> e
413413
// endregion
414414

415415
@Override
416-
protected Mono<String> getVendor() {
416+
public Mono<String> getVendor() {
417417
return Mono.just("Elasticsearch");
418418
}
419419

420420
@Override
421-
protected Mono<String> getRuntimeLibraryVersion() {
421+
public Mono<String> getRuntimeLibraryVersion() {
422422
return Mono.just(Version.VERSION != null ? Version.VERSION.toString() : "null");
423423
}
424424

425425
@Override
426-
protected Mono<String> getClusterVersion() {
426+
public Mono<String> getClusterVersion() {
427427
return Mono.from(execute(ReactiveElasticsearchClient::info)).map(infoResponse -> infoResponse.version().number());
428428
}
429429

src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ public UpdateByQueryRequest documentUpdateByQueryRequest(UpdateQuery updateQuery
963963
.pipeline(updateQuery.getPipeline()) //
964964
.requestsPerSecond(
965965
updateQuery.getRequestsPerSecond() != null ? updateQuery.getRequestsPerSecond().longValue() : null) //
966-
.slices(slices(Long.valueOf(updateQuery.getSlices())));
966+
.slices(slices(updateQuery.getSlices() != null ? Long.valueOf(updateQuery.getSlices()) : null));
967967

968968
if (updateQuery.getAbortOnVersionConflict() != null) {
969969
ub.conflicts(updateQuery.getAbortOnVersionConflict() ? Conflicts.Abort : Conflicts.Proceed);

src/main/java/org/springframework/data/elasticsearch/core/AbstractReactiveElasticsearchTemplate.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,15 @@ public ElasticsearchPersistentEntity<?> getPersistentEntityFor(@Nullable Class<?
611611
* @return the vendor name of the used cluster and client library
612612
* @since 4.3
613613
*/
614-
abstract protected Mono<String> getVendor();
614+
public abstract Mono<String> getVendor();
615615

616616
/**
617617
* @return the version of the used client runtime library.
618618
* @since 4.3
619619
*/
620-
abstract protected Mono<String> getRuntimeLibraryVersion();
620+
public abstract Mono<String> getRuntimeLibraryVersion();
621621

622-
abstract protected Mono<String> getClusterVersion();
622+
public abstract Mono<String> getClusterVersion();
623623

624624
/**
625625
* Value class to capture client independent information from a response to an index request.

src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ protected SearchRequest prepareSearchRequest(SearchRequest request, boolean useS
676676

677677
// region Helper methods
678678
@Override
679-
protected Mono<String> getClusterVersion() {
679+
public Mono<String> getClusterVersion() {
680680
try {
681681
return Mono.from(execute(ReactiveElasticsearchClient::info))
682682
.map(mainResponse -> mainResponse.getVersion().toString());
@@ -689,7 +689,7 @@ protected Mono<String> getClusterVersion() {
689689
* @since 4.3
690690
*/
691691
@Override
692-
protected Mono<String> getVendor() {
692+
public Mono<String> getVendor() {
693693
return Mono.just("Elasticsearch");
694694
}
695695

@@ -698,7 +698,7 @@ protected Mono<String> getVendor() {
698698
* @since 4.3
699699
*/
700700
@Override
701-
protected Mono<String> getRuntimeLibraryVersion() {
701+
public Mono<String> getRuntimeLibraryVersion() {
702702
return Mono.just(Version.CURRENT.toString());
703703
}
704704

src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -510,36 +510,37 @@ Settings toSettings() {
510510
return new Settings();
511511
}
512512

513-
Settings settings = new Settings() //
514-
.append("index.number_of_shards", String.valueOf(shards))
515-
.append("index.number_of_replicas", String.valueOf(replicas));
513+
var index = new Settings() //
514+
.append("number_of_shards", String.valueOf(shards)) //
515+
.append("number_of_replicas", String.valueOf(replicas));
516516

517517
if (refreshIntervall != null) {
518-
settings.append("index.refresh_interval", refreshIntervall);
518+
index.append("refresh_interval", refreshIntervall);
519519
}
520520

521521
if (indexStoreType != null) {
522-
settings.append("index.store.type", indexStoreType);
522+
index.append("store", new Settings().append("type", indexStoreType));
523523
}
524524

525525
if (sortFields != null && sortFields.length > 0) {
526-
settings.append("index.sort.field", sortFields);
526+
var sort = new Settings().append("field", sortFields);
527527

528528
if (sortOrders != null && sortOrders.length > 0) {
529-
settings.append("index.sort.order", sortOrders);
529+
sort.append("order", sortOrders);
530530
}
531531

532532
if (sortModes != null && sortModes.length > 0) {
533-
settings.append("index.sort.mode", sortModes);
533+
sort.append("mode", sortModes);
534534
}
535535

536536
if (sortMissingValues != null && sortMissingValues.length > 0) {
537-
settings.append("index.sort.missing", sortMissingValues);
537+
sort.append("missing", sortMissingValues);
538538
}
539-
}
540539

541-
return settings; //
540+
index.append("sort", sort);
541+
}
542542

543+
return new Settings().append("index", index); //
543544
}
544545
}
545546

src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsELCIntegrationTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ IndexNameProvider indexNameProvider() {
3737
return new IndexNameProvider("runtime-fields-rest-template");
3838
}
3939
}
40+
41+
@Override
42+
public boolean newElasticsearchClient() {
43+
return true;
44+
}
4045
}

src/test/java/org/springframework/data/elasticsearch/core/RuntimeFieldsIntegrationTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import org.junit.jupiter.api.DisplayName;
2222
import org.junit.jupiter.api.Order;
2323
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.condition.DisabledIf;
2425
import org.springframework.beans.factory.annotation.Autowired;
2526
import org.springframework.data.annotation.Id;
27+
import org.springframework.data.elasticsearch.NewElasticsearchClientDevelopment;
2628
import org.springframework.data.elasticsearch.annotations.Document;
2729
import org.springframework.data.elasticsearch.annotations.Field;
2830
import org.springframework.data.elasticsearch.annotations.FieldType;
@@ -38,7 +40,7 @@
3840
* @author Peter-Josef Meisch
3941
*/
4042
@SpringIntegrationTest
41-
public abstract class RuntimeFieldsIntegrationTests {
43+
public abstract class RuntimeFieldsIntegrationTests implements NewElasticsearchClientDevelopment {
4244

4345
@Autowired private ElasticsearchOperations operations;
4446
@Autowired protected IndexNameProvider indexNameProvider;
@@ -58,6 +60,7 @@ void cleanup() {
5860
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete();
5961
}
6062

63+
@DisabledIf(value = "newElasticsearchClient", disabledReason = "todo #2171, ES issue 298")
6164
@Test // #1971
6265
@DisplayName("should use runtime-field from query in search")
6366
void shouldUseRuntimeFieldFromQueryInSearch() {

src/test/java/org/springframework/data/elasticsearch/core/indices/ReactiveIndexOperationsIntegrationTests.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.springframework.data.elasticsearch.annotations.FieldType;
4242
import org.springframework.data.elasticsearch.annotations.Mapping;
4343
import org.springframework.data.elasticsearch.annotations.Setting;
44-
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
44+
import org.springframework.data.elasticsearch.core.AbstractReactiveElasticsearchTemplate;
4545
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
4646
import org.springframework.data.elasticsearch.core.ReactiveIndexOperations;
4747
import org.springframework.data.elasticsearch.core.index.*;
@@ -61,7 +61,7 @@ public abstract class ReactiveIndexOperationsIntegrationTests implements NewElas
6161
private ReactiveIndexOperations indexOperations;
6262

6363
boolean rhlcWithCluster8() {
64-
var clusterVersion = ((AbstractElasticsearchTemplate) operations).getClusterVersion();
64+
var clusterVersion = ((AbstractReactiveElasticsearchTemplate) operations).getClusterVersion().block();
6565
return (oldElasticsearchClient() && clusterVersion != null && clusterVersion.startsWith("8"));
6666
}
6767

@@ -123,21 +123,22 @@ void shouldCreateIndexForEntity() {
123123
@Test // DATAES-678
124124
void shouldCreateIndexWithGivenSettings() {
125125

126-
org.springframework.data.elasticsearch.core.document.Document requiredSettings = org.springframework.data.elasticsearch.core.document.Document
127-
.create();
128-
requiredSettings.put("index.number_of_replicas", 3);
129-
requiredSettings.put("index.number_of_shards", 4);
130-
requiredSettings.put("index.refresh_interval", "5s");
126+
var index = new Settings() //
127+
.append("number_of_replicas", 3) //
128+
.append("number_of_shards", 4)//
129+
.append("refresh_interval", "5s");
130+
var requiredSettings = new Settings().append("index", index);
131131

132132
indexOperations.create(requiredSettings) //
133133
.as(StepVerifier::create) //
134134
.expectNext(true) //
135135
.verifyComplete();
136136

137137
indexOperations.getSettings().as(StepVerifier::create).consumeNextWith(settings -> {
138-
assertThat(settings.get("index.number_of_replicas")).isEqualTo("3");
139-
assertThat(settings.get("index.number_of_shards")).isEqualTo("4");
140-
assertThat(settings.get("index.refresh_interval")).isEqualTo("5s");
138+
var flattened = settings.flatten();
139+
assertThat(flattened.get("index.number_of_replicas")).isEqualTo("3");
140+
assertThat(flattened.get("index.number_of_shards")).isEqualTo("4");
141+
assertThat(flattened.get("index.refresh_interval")).isEqualTo("5s");
141142
}).verifyComplete();
142143
}
143144

src/test/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntityTests.java

+20-7
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,29 @@ void shouldErrorIfIndexSortingParametersDoNotHaveTheSameNumberOfArguments() {
177177
.isInstanceOf(IllegalArgumentException.class);
178178
}
179179

180-
@Test // #1719
180+
@Test // #1719, #2158
181181
@DisplayName("should write sort parameters to Settings object")
182182
void shouldWriteSortParametersToSettingsObject() throws JSONException {
183183

184-
String expected = "{\n" + //
185-
" \"index.sort.field\": [\"second_field\", \"first_field\"],\n" + //
186-
" \"index.sort.mode\": [\"max\", \"min\"],\n" + //
187-
" \"index.sort.order\": [\"desc\",\"asc\"],\n" + //
188-
" \"index.sort.missing\": [\"_last\",\"_first\"]\n" + //
189-
"}\n"; //
184+
String expected = """
185+
{
186+
"index": {
187+
"sort": {
188+
"field": [
189+
"second_field",
190+
"first_field"
191+
],
192+
"mode": [
193+
"max",
194+
"min"
195+
],
196+
"missing": [
197+
"_last",
198+
"_first"
199+
]
200+
}
201+
}
202+
} """;
190203

191204
ElasticsearchPersistentEntity<?> entity = elasticsearchConverter.get().getMappingContext()
192205
.getRequiredPersistentEntity(SettingsValidSortParameterSizes.class);

0 commit comments

Comments
 (0)