@@ -144,10 +144,37 @@ void shouldUseConverterOnParameters() throws Exception {
144
144
.isEqualTo ("{ 'bool' : { 'must' : { 'term' : { 'car' : 'Toyota-Prius' } } } }" );
145
145
}
146
146
147
+ @ Test // #2135
148
+ @ DisplayName ("should handle array-of-strings parameters correctly" )
149
+ void shouldHandleArrayOfStringsParametersCorrectly () throws Exception {
150
+
151
+ List <String > otherNames = Arrays .asList ("Wesley" , "Emmett" );
152
+
153
+ org .springframework .data .elasticsearch .core .query .Query query = createQuery ("findByOtherNames" , otherNames );
154
+
155
+ assertThat (query ).isInstanceOf (StringQuery .class );
156
+ assertThat (((StringQuery ) query ).getSource ())
157
+ .isEqualTo ("{ 'bool' : { 'must' : { 'terms' : { 'otherNames' : [\" Wesley\" ,\" Emmett\" ] } } } }" );
158
+ }
159
+
160
+ @ Test // #2135
161
+ @ DisplayName ("should handle array-of-Integers parameters correctly" )
162
+ void shouldHandleArrayOfIntegerParametersCorrectly () throws Exception {
163
+
164
+ List <Integer > ages = Arrays .asList (42 , 57 );
165
+
166
+ org .springframework .data .elasticsearch .core .query .Query query = createQuery ("findByAges" , ages );
167
+
168
+ assertThat (query ).isInstanceOf (StringQuery .class );
169
+ assertThat (((StringQuery ) query ).getSource ())
170
+ .isEqualTo ("{ 'bool' : { 'must' : { 'terms' : { 'ages' : [42,57] } } } }" );
171
+ }
172
+
147
173
private org .springframework .data .elasticsearch .core .query .Query createQuery (String methodName , Object ... args )
148
174
throws NoSuchMethodException {
149
175
150
- Class <?>[] argTypes = Arrays .stream (args ).map (Object ::getClass ).toArray (Class []::new );
176
+ Class <?>[] argTypes = Arrays .stream (args ).map (Object ::getClass )
177
+ .map (clazz -> Collection .class .isAssignableFrom (clazz ) ? List .class : clazz ).toArray (Class []::new );
151
178
ReactiveElasticsearchQueryMethod queryMethod = getQueryMethod (methodName , argTypes );
152
179
ReactiveElasticsearchStringQuery elasticsearchStringQuery = queryForMethod (queryMethod );
153
180
@@ -195,6 +222,12 @@ Person findWithRepeatedPlaceholder(String arg0, String arg1, String arg2, String
195
222
@ Query ("{ 'bool' : { 'must' : { 'term' : { 'car' : '?0' } } } }" )
196
223
Mono <Person > findByCar (Car car );
197
224
225
+ @ Query ("{ 'bool' : { 'must' : { 'terms' : { 'otherNames' : ?0 } } } }" )
226
+ Flux <Person > findByOtherNames (List <String > otherNames );
227
+
228
+ @ Query ("{ 'bool' : { 'must' : { 'terms' : { 'ages' : ?0 } } } }" )
229
+ Flux <Person > findByAges (List <Integer > ages );
230
+
198
231
}
199
232
200
233
/**
@@ -211,6 +244,8 @@ public class Person {
211
244
212
245
@ Nullable private String name ;
213
246
247
+ @ Nullable private List <String > otherNames ;
248
+
214
249
@ Nullable
215
250
@ Field (type = FieldType .Nested ) private List <Car > car ;
216
251
@@ -235,6 +270,15 @@ public void setName(String name) {
235
270
this .name = name ;
236
271
}
237
272
273
+ @ Nullable
274
+ public List <String > getOtherNames () {
275
+ return otherNames ;
276
+ }
277
+
278
+ public void setOtherNames (List <String > otherNames ) {
279
+ this .otherNames = otherNames ;
280
+ }
281
+
238
282
@ Nullable
239
283
public List <Car > getCar () {
240
284
return car ;
0 commit comments