Skip to content

Commit ccb7d23

Browse files
authored
Consider Pageable in stream repository method.
Original Pull Request #2721 Closes #2720
1 parent d905c81 commit ccb7d23

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

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

+28-35
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,10 @@ public PutMappingRequest indicesPutMappingRequest(IndexCoordinates indexCoordina
337337
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
338338
Assert.notNull(mapping, "mapping must not be null");
339339

340-
PutMappingRequest request = new PutMappingRequest.Builder() //
341-
.withJson(new StringReader(mapping.toJson())) //
342-
.index(Arrays.asList(indexCoordinates.getIndexNames())) //
340+
return new PutMappingRequest.Builder()
341+
.withJson(new StringReader(mapping.toJson()))
342+
.index(Arrays.asList(indexCoordinates.getIndexNames()))
343343
.build();
344-
345-
return request;
346344
}
347345

348346
public GetMappingRequest indicesGetMappingRequest(IndexCoordinates indexCoordinates) {
@@ -422,10 +420,7 @@ public co.elastic.clients.elasticsearch.indices.PutTemplateRequest indicesPutTem
422420

423421
if (parametersAliases != null) {
424422
for (String aliasName : parametersAliases) {
425-
builder.aliases(aliasName, aliasBuilder -> {
426-
427-
return buildAlias(parameters, aliasBuilder);
428-
});
423+
builder.aliases(aliasName, aliasBuilder -> buildAlias(parameters, aliasBuilder));
429424
}
430425
}
431426
});
@@ -860,11 +855,10 @@ public co.elastic.clients.elasticsearch.core.ReindexRequest reindex(ReindexReque
860855
StringBuilder sb = new StringBuilder(remote.getScheme());
861856
sb.append("://");
862857
sb.append(remote.getHost());
863-
sb.append(":");
858+
sb.append(':');
864859
sb.append(remote.getPort());
865860

866861
if (remote.getPathPrefix() != null) {
867-
sb.append("");
868862
sb.append(remote.getPathPrefix());
869863
}
870864

@@ -884,7 +878,7 @@ public co.elastic.clients.elasticsearch.core.ReindexRequest reindex(ReindexReque
884878
}
885879

886880
SourceFilter sourceFilter = source.getSourceFilter();
887-
if (sourceFilter != null) {
881+
if (sourceFilter != null && sourceFilter.getIncludes() != null) {
888882
s.sourceFields(Arrays.asList(sourceFilter.getIncludes()));
889883
}
890884
return s;
@@ -1038,8 +1032,8 @@ public DeleteByQueryRequest documentDeleteByQueryRequest(Query query, @Nullable
10381032
int val;
10391033
try {
10401034
val = Integer.parseInt(waitForActiveShards);
1041-
} catch (NumberFormatException var3) {
1042-
throw new IllegalArgumentException("cannot parse ActiveShardCount[" + waitForActiveShards + "]", var3);
1035+
} catch (NumberFormatException e) {
1036+
throw new IllegalArgumentException("cannot parse ActiveShardCount[" + waitForActiveShards + ']', e);
10431037
}
10441038
uqb.waitForActiveShards(wfa -> wfa.count(val));
10451039
}
@@ -1124,7 +1118,6 @@ public <T> SearchRequest searchRequest(Query query, @Nullable String routing, @N
11241118
IndexCoordinates indexCoordinates, boolean forCount, boolean forBatchedSearch,
11251119
@Nullable Long scrollTimeInMillis) {
11261120

1127-
String[] indexNames = indexCoordinates.getIndexNames();
11281121
Assert.notNull(query, "query must not be null");
11291122
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
11301123

@@ -1267,7 +1260,7 @@ public MsearchRequest searchMsearchRequest(
12671260

12681261
if (!isEmpty(query.getIndicesBoost())) {
12691262
bb.indicesBoost(query.getIndicesBoost().stream()
1270-
.map(indexBoost -> Map.of(indexBoost.getIndexName(), Double.valueOf(indexBoost.getBoost())))
1263+
.map(indexBoost -> Map.of(indexBoost.getIndexName(), (double) indexBoost.getBoost()))
12711264
.collect(Collectors.toList()));
12721265
}
12731266

@@ -1434,13 +1427,15 @@ private <T> void prepareSearchRequest(Query query, @Nullable String routing, @Nu
14341427
} else if (forBatchedSearch) {
14351428
// request_cache is not allowed on scroll requests.
14361429
builder.requestCache(null);
1437-
// limit the number of documents in a batch
1438-
builder.size(query.getReactiveBatchSize());
1430+
// limit the number of documents in a batch if not already set in a pageable
1431+
if (query.getPageable().isUnpaged()) {
1432+
builder.size(query.getReactiveBatchSize());
1433+
}
14391434
}
14401435

14411436
if (!isEmpty(query.getIndicesBoost())) {
14421437
builder.indicesBoost(query.getIndicesBoost().stream()
1443-
.map(indexBoost -> Map.of(indexBoost.getIndexName(), Double.valueOf(indexBoost.getBoost())))
1438+
.map(indexBoost -> Map.of(indexBoost.getIndexName(), (double) indexBoost.getBoost()))
14441439
.collect(Collectors.toList()));
14451440
}
14461441

@@ -1468,15 +1463,14 @@ private void addIndicesOptions(SearchRequest.Builder builder, IndicesOptions ind
14681463
}
14691464
});
14701465

1471-
builder.expandWildcards(indicesOptions.getExpandWildcards().stream().map(wildcardStates -> {
1472-
return switch (wildcardStates) {
1473-
case OPEN -> ExpandWildcard.Open;
1474-
case CLOSED -> ExpandWildcard.Closed;
1475-
case HIDDEN -> ExpandWildcard.Hidden;
1476-
case ALL -> ExpandWildcard.All;
1477-
case NONE -> ExpandWildcard.None;
1478-
};
1479-
}).collect(Collectors.toList()));
1466+
builder.expandWildcards(indicesOptions.getExpandWildcards().stream()
1467+
.map(wildcardStates -> switch (wildcardStates) {
1468+
case OPEN -> ExpandWildcard.Open;
1469+
case CLOSED -> ExpandWildcard.Closed;
1470+
case HIDDEN -> ExpandWildcard.Hidden;
1471+
case ALL -> ExpandWildcard.All;
1472+
case NONE -> ExpandWildcard.None;
1473+
}).collect(Collectors.toList()));
14801474
}
14811475

14821476
private Rescore getRescore(RescorerQuery rescorerQuery) {
@@ -1585,8 +1579,8 @@ private SortOptions getSortOptions(Sort.Order order, @Nullable ElasticsearchPers
15851579

15861580
@Nullable
15871581
private NestedSortValue getNestedSort(@Nullable Order.Nested nested,
1588-
ElasticsearchPersistentEntity<?> persistentEntity) {
1589-
return (nested == null) ? null
1582+
@Nullable ElasticsearchPersistentEntity<?> persistentEntity) {
1583+
return (nested == null || persistentEntity == null) ? null
15901584
: NestedSortValue.of(b -> b //
15911585
.path(elasticsearchConverter.updateFieldNames(nested.getPath(), persistentEntity)) //
15921586
.maxChildren(nested.getMaxChildren()) //
@@ -1682,7 +1676,8 @@ private void addFilter(Query query, SearchRequest.Builder builder) {
16821676

16831677
if (query instanceof CriteriaQuery) {
16841678
CriteriaFilterProcessor.createQuery(((CriteriaQuery) query).getCriteria()).ifPresent(builder::postFilter);
1685-
} else if (query instanceof StringQuery) {
1679+
} else //noinspection StatementWithEmptyBody
1680+
if (query instanceof StringQuery) {
16861681
// no filter for StringQuery
16871682
} else if (query instanceof NativeQuery) {
16881683
builder.postFilter(((NativeQuery) query).getFilter());
@@ -1697,7 +1692,7 @@ public co.elastic.clients.elasticsearch._types.query_dsl.MoreLikeThisQuery moreL
16971692
Assert.notNull(query, "query must not be null");
16981693
Assert.notNull(index, "index must not be null");
16991694

1700-
co.elastic.clients.elasticsearch._types.query_dsl.MoreLikeThisQuery moreLikeThisQuery = co.elastic.clients.elasticsearch._types.query_dsl.MoreLikeThisQuery
1695+
return co.elastic.clients.elasticsearch._types.query_dsl.MoreLikeThisQuery
17011696
.of(q -> {
17021697
q.like(Like.of(l -> l.document(ld -> ld.index(index.getIndexName()).id(query.getId()))))
17031698
.fields(query.getFields());
@@ -1736,8 +1731,6 @@ public co.elastic.clients.elasticsearch._types.query_dsl.MoreLikeThisQuery moreL
17361731

17371732
return q;
17381733
});
1739-
1740-
return moreLikeThisQuery;
17411734
}
17421735

17431736
public OpenPointInTimeRequest searchOpenPointInTimeRequest(IndexCoordinates index, Duration keepAlive,
@@ -1783,7 +1776,7 @@ public SearchTemplateRequest searchTemplate(SearchTemplateQuery query, @Nullable
17831776
}
17841777

17851778
var expandWildcards = query.getExpandWildcards();
1786-
if (!expandWildcards.isEmpty()) {
1779+
if (expandWildcards != null && !expandWildcards.isEmpty()) {
17871780
builder.expandWildcards(expandWildcards(expandWildcards));
17881781
}
17891782

src/main/java/org/springframework/data/elasticsearch/core/query/Query.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ default Integer getReactiveBatchSize() {
469469
/**
470470
* @since 5.1
471471
*/
472-
EnumSet<IndicesOptions.WildcardStates> getExpandWildcards();
472+
@Nullable EnumSet<IndicesOptions.WildcardStates> getExpandWildcards();
473473

474474
/**
475475
* @return a possible empty list of docvalue_field values to be set on the query.

0 commit comments

Comments
 (0)