Skip to content

Commit a4c1505

Browse files
committed
DATAES-938 - Fix collection query detection in ReactiveElasticsearchQueryMethod.
isCollectionQuery() now correctly identifies if a query should return more than one result.
1 parent 7117e5d commit a4c1505

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchQueryMethod.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.data.repository.util.ReactiveWrapperConverters;
3737
import org.springframework.data.repository.util.ReactiveWrappers;
3838
import org.springframework.data.util.ClassTypeInformation;
39+
import org.springframework.data.util.Lazy;
3940
import org.springframework.data.util.TypeInformation;
4041
import org.springframework.util.ClassUtils;
4142

@@ -48,6 +49,7 @@ public class ReactiveElasticsearchQueryMethod extends ElasticsearchQueryMethod {
4849

4950
private static final ClassTypeInformation<Page> PAGE_TYPE = ClassTypeInformation.from(Page.class);
5051
private static final ClassTypeInformation<Slice> SLICE_TYPE = ClassTypeInformation.from(Slice.class);
52+
private final Lazy<Boolean> isCollectionQuery;
5153

5254
public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
5355
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
@@ -80,6 +82,9 @@ public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metada
8082
+ "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
8183
}
8284
}
85+
86+
this.isCollectionQuery = Lazy.of(() -> (!(isPageQuery() || isSliceQuery())
87+
&& ReactiveWrappers.isMultiValueType(metadata.getReturnType(method).getType()) || super.isCollectionQuery()));
8388
}
8489

8590
@Override
@@ -103,6 +108,15 @@ public boolean hasReactiveWrapperParameter() {
103108
return false;
104109
}
105110

111+
/*
112+
* (non-Javadoc)
113+
* @see org.springframework.data.repository.query.QueryMethod#isCollectionQuery()
114+
*/
115+
@Override
116+
public boolean isCollectionQuery() {
117+
return isCollectionQuery.get();
118+
}
119+
106120
/*
107121
* (non-Javadoc)
108122
* @see org.springframework.data.repository.query.QueryMethod#isStreamQuery()

0 commit comments

Comments
 (0)