@@ -144,14 +144,29 @@ void shouldUseConverterOnParameters() throws Exception {
144
144
.isEqualTo ("{ 'bool' : { 'must' : { 'term' : { 'car' : 'Toyota-Prius' } } } }" );
145
145
}
146
146
147
+ @ Test // #1866
148
+ @ DisplayName ("should handle array-of-strings parameters correctly" )
149
+ void shouldHandleArrayOfStringsParametersCorrectly () throws Exception {
150
+
151
+ List <String > otherNames = List .of ("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
+
147
160
private org .springframework .data .elasticsearch .core .query .Query createQuery (String methodName , Object ... args )
148
161
throws NoSuchMethodException {
149
162
150
- Class <?>[] argTypes = Arrays .stream (args ).map (Object ::getClass ).toArray (Class []::new );
163
+ Class <?>[] argTypes = Arrays .stream (args ).map (Object ::getClass )
164
+ .map (clazz -> Collection .class .isAssignableFrom (clazz ) ? List .class : clazz ).toArray (Class []::new );
151
165
ReactiveElasticsearchQueryMethod queryMethod = getQueryMethod (methodName , argTypes );
152
166
ReactiveElasticsearchStringQuery elasticsearchStringQuery = queryForMethod (queryMethod );
153
167
154
- return elasticsearchStringQuery .createQuery (new ElasticsearchParametersParameterAccessor (queryMethod , args ));
168
+ return elasticsearchStringQuery .createQuery (new ConvertingParameterAccessor (operations .getElasticsearchConverter (),
169
+ new ElasticsearchParametersParameterAccessor (queryMethod , args )));
155
170
}
156
171
157
172
private ReactiveElasticsearchStringQuery queryForMethod (ReactiveElasticsearchQueryMethod queryMethod ) {
@@ -195,6 +210,9 @@ Person findWithRepeatedPlaceholder(String arg0, String arg1, String arg2, String
195
210
@ Query ("{ 'bool' : { 'must' : { 'term' : { 'car' : '?0' } } } }" )
196
211
Mono <Person > findByCar (Car car );
197
212
213
+ @ Query ("{ 'bool' : { 'must' : { 'terms' : { 'otherNames' : ?0 } } } }" )
214
+ Flux <Person > findByOtherNames (List <String > otherNames );
215
+
198
216
}
199
217
200
218
/**
@@ -211,6 +229,8 @@ public class Person {
211
229
212
230
@ Nullable private String name ;
213
231
232
+ @ Nullable private List <String > otherNames ;
233
+
214
234
@ Nullable
215
235
@ Field (type = FieldType .Nested ) private List <Car > car ;
216
236
@@ -235,6 +255,15 @@ public void setName(String name) {
235
255
this .name = name ;
236
256
}
237
257
258
+ @ Nullable
259
+ public List <String > getOtherNames () {
260
+ return otherNames ;
261
+ }
262
+
263
+ public void setOtherNames (List <String > otherNames ) {
264
+ this .otherNames = otherNames ;
265
+ }
266
+
238
267
@ Nullable
239
268
public List <Car > getCar () {
240
269
return car ;
0 commit comments