Skip to content

Commit 474ff84

Browse files
diamondTsothawo
authored andcommittedJul 12, 2022
Fix handling of array-of-strings parameters for @Query-annotated queries.
Original Pull Request #2182 Closes #2135 (cherry picked from commit 259c43a) (cherry picked from commit aa4aeca)
·
4.3.104.3.6
1 parent c58e3b3 commit 474ff84

File tree

4 files changed

+228
-170
lines changed

4 files changed

+228
-170
lines changed
 

‎src/main/java/org/springframework/data/elasticsearch/repository/query/AbstractReactiveElasticsearchRepositoryQuery.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ private Object execute(ElasticsearchParameterAccessor parameterAccessor) {
8282

8383
ResultProcessor processor = queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor);
8484

85-
Query query = createQuery(
86-
new ConvertingParameterAccessor(elasticsearchOperations.getElasticsearchConverter(), parameterAccessor));
85+
Query query = createQuery(parameterAccessor);
8786

8887
if (queryMethod.hasAnnotatedHighlight()) {
8988
query.setHighlightQuery(queryMethod.getAnnotatedHighlightQuery());

‎src/main/java/org/springframework/data/elasticsearch/repository/query/ConvertingParameterAccessor.java

Lines changed: 0 additions & 95 deletions
This file was deleted.

‎src/test/java/org/springframework/data/elasticsearch/repository/query/ReactiveElasticsearchStringQueryUnitTests.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2021 the original author or authors.
2+
* Copyright 2019-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -144,10 +144,37 @@ void shouldUseConverterOnParameters() throws Exception {
144144
.isEqualTo("{ 'bool' : { 'must' : { 'term' : { 'car' : 'Toyota-Prius' } } } }");
145145
}
146146

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+
147173
private org.springframework.data.elasticsearch.core.query.Query createQuery(String methodName, Object... args)
148174
throws NoSuchMethodException {
149175

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);
151178
ReactiveElasticsearchQueryMethod queryMethod = getQueryMethod(methodName, argTypes);
152179
ReactiveElasticsearchStringQuery elasticsearchStringQuery = queryForMethod(queryMethod);
153180

@@ -195,6 +222,12 @@ Person findWithRepeatedPlaceholder(String arg0, String arg1, String arg2, String
195222
@Query("{ 'bool' : { 'must' : { 'term' : { 'car' : '?0' } } } }")
196223
Mono<Person> findByCar(Car car);
197224

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+
198231
}
199232

200233
/**
@@ -206,10 +239,13 @@ Person findWithRepeatedPlaceholder(String arg0, String arg1, String arg2, String
206239
@Document(indexName = "test-index-person-reactive-repository-string-query")
207240
public class Person {
208241

209-
@Nullable @Id private String id;
242+
@Nullable
243+
@Id private String id;
210244

211245
@Nullable private String name;
212246

247+
@Nullable private List<String> otherNames;
248+
213249
@Nullable @Field(type = FieldType.Nested) private List<Car> car;
214250

215251
@Nullable @Field(type = FieldType.Nested, includeInParent = true) private List<Book> books;
@@ -232,6 +268,15 @@ public void setName(String name) {
232268
this.name = name;
233269
}
234270

271+
@Nullable
272+
public List<String> getOtherNames() {
273+
return otherNames;
274+
}
275+
276+
public void setOtherNames(List<String> otherNames) {
277+
this.otherNames = otherNames;
278+
}
279+
235280
@Nullable
236281
public List<Car> getCar() {
237282
return car;

‎src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryTests.java

Lines changed: 179 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
2020
import static org.springframework.data.elasticsearch.core.query.Query.*;
2121

22+
import org.springframework.data.elasticsearch.annotations.FieldType;
2223
import reactor.core.publisher.Flux;
2324
import reactor.core.publisher.Mono;
2425
import reactor.test.StepVerifier;
@@ -91,7 +92,8 @@ void after() {
9192
operations.indexOps(IndexCoordinates.of(INDEX)).delete().block();
9293
}
9394

94-
@Test // DATAES-519
95+
@Test
96+
// DATAES-519
9597
void saveShouldSaveSingleEntity() {
9698

9799
repository.save(new SampleEntity()) //
@@ -105,7 +107,8 @@ private Mono<Boolean> documentWithIdExistsInIndex(String id) {
105107
return operations.exists(id, IndexCoordinates.of(INDEX));
106108
}
107109

108-
@Test // DATAES-519
110+
@Test
111+
// DATAES-519
109112
void saveShouldComputeMultipleEntities() {
110113

111114
repository.saveAll(Arrays.asList(new SampleEntity(), new SampleEntity(), new SampleEntity()))
@@ -118,65 +121,71 @@ void saveShouldComputeMultipleEntities() {
118121
.verifyComplete();
119122
}
120123

121-
@Test // DATAES-519, DATAES-767, DATAES-822
124+
@Test
125+
// DATAES-519, DATAES-767, DATAES-822
122126
void findByIdShouldErrorIfIndexDoesNotExist() {
123127
repository.findById("id-two") //
124128
.as(StepVerifier::create) //
125129
.expectError(RestStatusException.class);
126130
}
127131

128-
@Test // DATAES-519
132+
@Test
133+
// DATAES-519
129134
void findShouldRetrieveSingleEntityById() {
130135

131136
bulkIndex(new SampleEntity("id-one"), //
132137
new SampleEntity("id-two"), //
133138
new SampleEntity("id-three")) //
134-
.block();
139+
.block();
135140

136141
repository.findById("id-two").as(StepVerifier::create)//
137142
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-two")) //
138143
.verifyComplete();
139144
}
140145

141-
@Test // DATAES-519
146+
@Test
147+
// DATAES-519
142148
void findByIdShouldCompleteIfNothingFound() {
143149

144150
bulkIndex(new SampleEntity("id-one"), //
145151
new SampleEntity("id-two"), //
146152
new SampleEntity("id-three")) //
147-
.block();
153+
.block();
148154

149155
repository.findById("does-not-exist").as(StepVerifier::create) //
150156
.verifyComplete();
151157
}
152158

153-
@Test // DATAES-720
159+
@Test
160+
// DATAES-720
154161
void findAllShouldReturnAllElements() {
155162
// make sure to be above the default page size of the Query interface
156163
int count = DEFAULT_PAGE_SIZE * 2;
157164
bulkIndex(IntStream.range(1, count + 1) //
158165
.mapToObj(it -> new SampleEntity(String.valueOf(it))) //
159166
.toArray(SampleEntity[]::new)) //
160-
.block();
167+
.block();
161168

162169
repository.findAll() //
163170
.as(StepVerifier::create) //
164171
.expectNextCount(count) //
165172
.verifyComplete();
166173
}
167174

168-
@Test // DATAES-519
175+
@Test
176+
// DATAES-519
169177
void findAllByIdByIdShouldCompleteIfIndexDoesNotExist() {
170178
repository.findAllById(Arrays.asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete();
171179
}
172180

173-
@Test // DATAES-519
181+
@Test
182+
// DATAES-519
174183
void findAllByIdShouldRetrieveMatchingDocuments() {
175184

176185
bulkIndex(new SampleEntity("id-one"), //
177186
new SampleEntity("id-two"), //
178187
new SampleEntity("id-three")) //
179-
.block();
188+
.block();
180189

181190
repository.findAllById(Arrays.asList("id-one", "id-two")) //
182191
.as(StepVerifier::create)//
@@ -185,26 +194,28 @@ void findAllByIdShouldRetrieveMatchingDocuments() {
185194
.verifyComplete();
186195
}
187196

188-
@Test // DATAES-519
197+
@Test
198+
// DATAES-519
189199
void findAllByIdShouldCompleteWhenNothingFound() {
190200

191201
bulkIndex(new SampleEntity("id-one"), //
192202
new SampleEntity("id-two"), //
193203
new SampleEntity("id-three")) //
194-
.block();
204+
.block();
195205

196206
repository.findAllById(Arrays.asList("can't", "touch", "this")) //
197207
.as(StepVerifier::create)//
198208
.verifyComplete();
199209
}
200210

201-
@Test // DATAES-717
211+
@Test
212+
// DATAES-717
202213
void shouldReturnFluxOfSearchHit() {
203214

204215
bulkIndex(new SampleEntity("id-one", "message"), //
205216
new SampleEntity("id-two", "message"), //
206217
new SampleEntity("id-three", "message")) //
207-
.block();
218+
.block();
208219

209220
repository.queryAllByMessage("message") //
210221
.as(StepVerifier::create) //
@@ -213,13 +224,14 @@ void shouldReturnFluxOfSearchHit() {
213224
.verifyComplete();
214225
}
215226

216-
@Test // DATAES-717
227+
@Test
228+
// DATAES-717
217229
void shouldReturnFluxOfSearchHitForStringQuery() {
218230

219231
bulkIndex(new SampleEntity("id-one", "message"), //
220232
new SampleEntity("id-two", "message"), //
221233
new SampleEntity("id-three", "message")) //
222-
.block();
234+
.block();
223235

224236
repository.queryByMessageWithString("message") //
225237
.as(StepVerifier::create) //
@@ -228,13 +240,14 @@ void shouldReturnFluxOfSearchHitForStringQuery() {
228240
.verifyComplete();
229241
}
230242

231-
@Test // DATAES-372
243+
@Test
244+
// DATAES-372
232245
void shouldReturnHighlightsOnAnnotatedMethod() {
233246

234247
bulkIndex(new SampleEntity("id-one", "message"), //
235248
new SampleEntity("id-two", "message"), //
236249
new SampleEntity("id-three", "message")) //
237-
.block();
250+
.block();
238251

239252
repository.queryAllByMessage("message") //
240253
.as(StepVerifier::create) //
@@ -246,13 +259,14 @@ void shouldReturnHighlightsOnAnnotatedMethod() {
246259
.verifyComplete();
247260
}
248261

249-
@Test // DATAES-372
262+
@Test
263+
// DATAES-372
250264
void shouldReturnHighlightsOnAnnotatedStringQueryMethod() {
251265

252266
bulkIndex(new SampleEntity("id-one", "message"), //
253267
new SampleEntity("id-two", "message"), //
254268
new SampleEntity("id-three", "message")) //
255-
.block();
269+
.block();
256270

257271
repository.queryByMessageWithString("message") //
258272
.as(StepVerifier::create) //
@@ -264,52 +278,57 @@ void shouldReturnHighlightsOnAnnotatedStringQueryMethod() {
264278
.verifyComplete();
265279
}
266280

267-
@Test // DATAES-519, DATAES-767, DATAES-822
281+
@Test
282+
// DATAES-519, DATAES-767, DATAES-822
268283
void countShouldErrorWhenIndexDoesNotExist() {
269284
repository.count() //
270285
.as(StepVerifier::create) //
271286
.expectError(RestStatusException.class);
272287
}
273288

274-
@Test // DATAES-519
289+
@Test
290+
// DATAES-519
275291
void countShouldCountDocuments() {
276292

277293
bulkIndex(new SampleEntity("id-one"), //
278294
new SampleEntity("id-two")) //
279-
.block();
295+
.block();
280296

281297
repository.count().as(StepVerifier::create).expectNext(2L).verifyComplete();
282298
}
283299

284-
@Test // DATAES-519
300+
@Test
301+
// DATAES-519
285302
void existsByIdShouldReturnTrueIfExists() {
286303

287304
bulkIndex(new SampleEntity("id-one", "message"), //
288305
new SampleEntity("id-two", "test message"), //
289306
new SampleEntity("id-three", "test test")) //
290-
.block();
307+
.block();
291308

292309
repository.existsById("id-two") //
293310
.as(StepVerifier::create) //
294311
.expectNext(true) //
295312
.verifyComplete();
296313
}
297314

298-
@Test // DATAES-519
315+
@Test
316+
// DATAES-519
299317
void existsByIdShouldReturnFalseIfNotExists() {
300318

301319
bulkIndex(new SampleEntity("id-one", "message"), //
302320
new SampleEntity("id-two", "test message"), //
303321
new SampleEntity("id-three", "test test")) //
304-
.block();
322+
.block();
305323

306324
repository.existsById("wrecking ball") //
307325
.as(StepVerifier::create) //
308326
.expectNext(false) //
309327
.verifyComplete();
310328
}
311329

312-
@Test // DATAES-519
330+
@Test
331+
// DATAES-519
313332
void countShouldCountMatchingDocuments() {
314333

315334
bulkIndex(new SampleEntity("id-one", "message"), //
@@ -336,52 +355,57 @@ void shouldCountWithStringQuery() {
336355
.verifyComplete();
337356
}
338357

339-
@Test // DATAES-519
358+
@Test
359+
// DATAES-519
340360
void existsShouldReturnTrueIfExists() {
341361

342362
bulkIndex(new SampleEntity("id-one", "message"), //
343363
new SampleEntity("id-two", "test message"), //
344364
new SampleEntity("id-three", "test test")) //
345-
.block();
365+
.block();
346366

347367
repository.existsAllByMessage("message") //
348368
.as(StepVerifier::create) //
349369
.expectNext(true) //
350370
.verifyComplete();
351371
}
352372

353-
@Test // DATAES-519
373+
@Test
374+
// DATAES-519
354375
void existsShouldReturnFalseIfNotExists() {
355376

356377
bulkIndex(new SampleEntity("id-one", "message"), //
357378
new SampleEntity("id-two", "test message"), //
358379
new SampleEntity("id-three", "test test")) //
359-
.block();
380+
.block();
360381

361382
repository.existsAllByMessage("these days") //
362383
.as(StepVerifier::create) //
363384
.expectNext(false) //
364385
.verifyComplete();
365386
}
366387

367-
@Test // DATAES-519
388+
@Test
389+
// DATAES-519
368390
void deleteByIdShouldCompleteIfNothingDeleted() {
369391

370392
bulkIndex(new SampleEntity("id-one"), //
371393
new SampleEntity("id-two")) //
372-
.block();
394+
.block();
373395

374396
repository.deleteById("does-not-exist").as(StepVerifier::create).verifyComplete();
375397
}
376398

377-
@Test // DATAES-519, DATAES-767, DATAES-822, DATAES-678
399+
@Test
400+
// DATAES-519, DATAES-767, DATAES-822, DATAES-678
378401
void deleteByIdShouldCompleteWhenIndexDoesNotExist() {
379402
repository.deleteById("does-not-exist") //
380403
.as(StepVerifier::create) //
381404
.verifyComplete();
382405
}
383406

384-
@Test // DATAES-519
407+
@Test
408+
// DATAES-519
385409
void deleteByIdShouldDeleteEntry() {
386410

387411
SampleEntity toBeDeleted = new SampleEntity("id-two");
@@ -393,19 +417,22 @@ void deleteByIdShouldDeleteEntry() {
393417
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
394418
}
395419

396-
@Test // DATAES-976
420+
@Test
421+
// DATAES-976
397422
void deleteAllByIdShouldDeleteEntry() {
398423

399424
SampleEntity toBeDeleted = new SampleEntity("id-two");
400425
bulkIndex(new SampleEntity("id-one"), toBeDeleted) //
401426
.block();
402427

403-
repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete();
428+
repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create)
429+
.verifyComplete();
404430

405431
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
406432
}
407433

408-
@Test // DATAES-519
434+
@Test
435+
// DATAES-519
409436
void deleteShouldDeleteEntry() {
410437

411438
SampleEntity toBeDeleted = new SampleEntity("id-two");
@@ -417,7 +444,8 @@ void deleteShouldDeleteEntry() {
417444
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
418445
}
419446

420-
@Test // DATAES-519
447+
@Test
448+
// DATAES-519
421449
void deleteAllShouldDeleteGivenEntries() {
422450

423451
SampleEntity toBeDeleted = new SampleEntity("id-one");
@@ -434,13 +462,14 @@ void deleteAllShouldDeleteGivenEntries() {
434462
assertThat(documentWithIdExistsInIndex(hangInThere.getId()).block()).isTrue();
435463
}
436464

437-
@Test // DATAES-519
465+
@Test
466+
// DATAES-519
438467
void deleteAllShouldDeleteAllEntries() {
439468

440469
bulkIndex(new SampleEntity("id-one"), //
441470
new SampleEntity("id-two"), //
442471
new SampleEntity("id-three")) //
443-
.block();
472+
.block();
444473

445474
repository.deleteAll().as(StepVerifier::create).verifyComplete();
446475

@@ -450,41 +479,44 @@ void deleteAllShouldDeleteAllEntries() {
450479
.verifyComplete();
451480
}
452481

453-
@Test // DATAES-519
482+
@Test
483+
// DATAES-519
454484
void derivedFinderMethodShouldBeExecutedCorrectly() {
455485

456486
bulkIndex(new SampleEntity("id-one", "message"), //
457487
new SampleEntity("id-two", "test message"), //
458488
new SampleEntity("id-three", "test test")) //
459-
.block();
489+
.block();
460490

461491
repository.findAllByMessageLike("test") //
462492
.as(StepVerifier::create) //
463493
.expectNextCount(2) //
464494
.verifyComplete();
465495
}
466496

467-
@Test // DATAES-519
497+
@Test
498+
// DATAES-519
468499
void derivedFinderMethodShouldBeExecutedCorrectlyWhenGivenPublisher() {
469500

470501
bulkIndex(new SampleEntity("id-one", "message"), //
471502
new SampleEntity("id-two", "test message"), //
472503
new SampleEntity("id-three", "test test")) //
473-
.block();
504+
.block();
474505

475506
repository.findAllByMessage(Mono.just("test")) //
476507
.as(StepVerifier::create) //
477508
.expectNextCount(2) //
478509
.verifyComplete();
479510
}
480511

481-
@Test // DATAES-519
512+
@Test
513+
// DATAES-519
482514
void derivedFinderWithDerivedSortMethodShouldBeExecutedCorrectly() {
483515

484516
bulkIndex(new SampleEntity("id-one", "test", 3), //
485517
new SampleEntity("id-two", "test test", 1), //
486518
new SampleEntity("id-three", "test test", 2)) //
487-
.block();
519+
.block();
488520

489521
repository.findAllByMessageLikeOrderByRate("test") //
490522
.as(StepVerifier::create) //
@@ -494,13 +526,14 @@ void derivedFinderWithDerivedSortMethodShouldBeExecutedCorrectly() {
494526
.verifyComplete();
495527
}
496528

497-
@Test // DATAES-519
529+
@Test
530+
// DATAES-519
498531
void derivedFinderMethodWithSortParameterShouldBeExecutedCorrectly() {
499532

500533
bulkIndex(new SampleEntity("id-one", "test", 3), //
501534
new SampleEntity("id-two", "test test", 1), //
502535
new SampleEntity("id-three", "test test", 2)) //
503-
.block();
536+
.block();
504537

505538
repository.findAllByMessage("test", Sort.by(Order.asc("rate"))) //
506539
.as(StepVerifier::create) //
@@ -510,13 +543,14 @@ void derivedFinderMethodWithSortParameterShouldBeExecutedCorrectly() {
510543
.verifyComplete();
511544
}
512545

513-
@Test // DATAES-519
546+
@Test
547+
// DATAES-519
514548
void derivedFinderMethodWithPageableParameterShouldBeExecutedCorrectly() {
515549

516550
bulkIndex(new SampleEntity("id-one", "test", 3), //
517551
new SampleEntity("id-two", "test test", 1), //
518552
new SampleEntity("id-three", "test test", 2)) //
519-
.block();
553+
.block();
520554

521555
repository.findAllByMessage("test", PageRequest.of(0, 2, Sort.by(Order.asc("rate")))) //
522556
.as(StepVerifier::create) //
@@ -525,21 +559,23 @@ void derivedFinderMethodWithPageableParameterShouldBeExecutedCorrectly() {
525559
.verifyComplete();
526560
}
527561

528-
@Test // DATAES-519
562+
@Test
563+
// DATAES-519
529564
void derivedFinderMethodReturningMonoShouldBeExecutedCorrectly() {
530565

531566
bulkIndex(new SampleEntity("id-one", "message"), //
532567
new SampleEntity("id-two", "test message"), //
533568
new SampleEntity("id-three", "test test")) //
534-
.block();
569+
.block();
535570

536571
repository.findFirstByMessageLike("test") //
537572
.as(StepVerifier::create) //
538573
.expectNextCount(1) //
539574
.verifyComplete();
540575
}
541576

542-
@Test // DATAES-519
577+
@Test
578+
// DATAES-519
543579
void annotatedFinderMethodShouldBeExecutedCorrectly() {
544580

545581
int count = 30;
@@ -555,7 +591,8 @@ void annotatedFinderMethodShouldBeExecutedCorrectly() {
555591
.verifyComplete();
556592
}
557593

558-
@Test // #1917
594+
@Test
595+
// #1917
559596
void annotatedFinderMethodPagedShouldBeExecutedCorrectly() {
560597

561598
int count = 30;
@@ -575,13 +612,14 @@ void annotatedFinderMethodPagedShouldBeExecutedCorrectly() {
575612
.verifyComplete();
576613
}
577614

578-
@Test // DATAES-519
615+
@Test
616+
// DATAES-519
579617
void derivedDeleteMethodShouldBeExecutedCorrectly() {
580618

581619
bulkIndex(new SampleEntity("id-one", "message"), //
582620
new SampleEntity("id-two", "test message"), //
583621
new SampleEntity("id-three", "test test")) //
584-
.block();
622+
.block();
585623

586624
repository.deleteAllByMessage("message") //
587625
.as(StepVerifier::create) //
@@ -593,6 +631,56 @@ void derivedDeleteMethodShouldBeExecutedCorrectly() {
593631
assertThat(documentWithIdExistsInIndex("id-three").block()).isTrue();
594632
}
595633

634+
@Test
635+
// #2135
636+
void FluxOfSearchHitForArrayQuery() {
637+
bulkIndex(new SampleEntity("id-one", "message1"), //
638+
new SampleEntity("id-two", "message2"), //
639+
new SampleEntity("id-three", "message3")) //
640+
.block();
641+
642+
repository.findAllViaAnnotatedQueryByMessageIn(Arrays.asList("message1", "message3")) //
643+
.as(StepVerifier::create) //
644+
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-one")) //
645+
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-three")) //
646+
.verifyComplete();
647+
648+
}
649+
650+
@Test
651+
// #2135
652+
void FluxOfSearchHitForIntegerArrayQuery() {
653+
bulkIndex(new SampleEntity("id-one", "test", 3), //
654+
new SampleEntity("id-two", "test test", 1), //
655+
new SampleEntity("id-three", "test test", 2)) //
656+
.block();
657+
658+
repository.findAllViaAnnotatedQueryByRatesIn(Arrays.asList(2, 3)) //
659+
.as(StepVerifier::create) //
660+
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-one")) //
661+
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-three")) //
662+
.verifyComplete();
663+
664+
}
665+
666+
@Test
667+
// #2135
668+
void FluxOfSearchHitForStringAndIntegerArrayQuery() {
669+
bulkIndex(new SampleEntity("id-one", "message1", 1), //
670+
new SampleEntity("id-two", "message2", 2), //
671+
new SampleEntity("id-three", "message3", 3), //
672+
new SampleEntity("id-four", "message4", 4), //
673+
new SampleEntity("id-five", "message5", 5)) //
674+
.block();
675+
676+
repository.findAllViaAnnotatedQueryByMessageInAndRatesIn(Arrays.asList("message5", "message3"), Arrays.asList(2,
677+
3)) //
678+
.as(StepVerifier::create) //
679+
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-three")) //
680+
.verifyComplete();
681+
682+
}
683+
596684
Mono<Void> bulkIndex(SampleEntity... entities) {
597685
return operations.saveAll(Arrays.asList(entities), IndexCoordinates.of(INDEX)).then();
598686
}
@@ -609,11 +697,11 @@ interface ReactiveSampleEntityRepository extends ReactiveCrudRepository<SampleEn
609697

610698
Flux<SampleEntity> findAllByMessage(Publisher<String> message);
611699

612-
@Highlight(fields = { @HighlightField(name = "message") })
700+
@Highlight(fields = {@HighlightField(name = "message")})
613701
Flux<SearchHit<SampleEntity>> queryAllByMessage(String message);
614702

615703
@Query("{\"bool\": {\"must\": [{\"term\": {\"message\": \"?0\"}}]}}")
616-
@Highlight(fields = { @HighlightField(name = "message") })
704+
@Highlight(fields = {@HighlightField(name = "message")})
617705
Flux<SearchHit<SampleEntity>> queryByMessageWithString(String message);
618706

619707
@Query("{ \"bool\" : { \"must\" : { \"term\" : { \"message\" : \"?0\" } } } }")
@@ -632,18 +720,39 @@ interface ReactiveSampleEntityRepository extends ReactiveCrudRepository<SampleEn
632720

633721
@CountQuery(value = "{\"bool\": {\"must\": [{\"term\": {\"message\": \"?0\"}}]}}")
634722
Mono<Long> retrieveCountByText(String message);
723+
724+
@Query("{ \"terms\": { \"message\": ?0 } }")
725+
Flux<SampleEntity> findAllViaAnnotatedQueryByMessageIn(List<String> messages);
726+
727+
@Query("{ \"terms\": { \"rate\": ?0 } }")
728+
Flux<SampleEntity> findAllViaAnnotatedQueryByRatesIn(List<Integer> rates);
729+
730+
@Query("{\"bool\": {\"must\": [{ \"terms\": { \"message\": ?0 } }, { \"terms\": { \"rate\": ?1 } }] } }")
731+
Flux<SampleEntity> findAllViaAnnotatedQueryByMessageInAndRatesIn(List<String> messages, List<Integer> rates);
732+
635733
}
636734

637735
@Document(indexName = INDEX)
638736
static class SampleEntity {
639-
@Nullable @Id private String id;
640-
@Nullable @Field(type = Text, store = true, fielddata = true) private String type;
641-
@Nullable @Field(type = Text, store = true, fielddata = true) private String message;
642-
@Nullable private int rate;
643-
@Nullable private boolean available;
644-
@Nullable @Version private Long version;
645-
646-
public SampleEntity() {}
737+
@Nullable
738+
@Id
739+
private String id;
740+
@Nullable
741+
@Field(type = FieldType.Text, store = true, fielddata = true)
742+
private String type;
743+
@Nullable
744+
@Field(type = FieldType.Text, store = true, fielddata = true)
745+
private String message;
746+
@Nullable
747+
private int rate;
748+
@Nullable
749+
private boolean available;
750+
@Nullable
751+
@Version
752+
private Long version;
753+
754+
public SampleEntity() {
755+
}
647756

648757
public SampleEntity(@Nullable String id) {
649758
this.id = id;

0 commit comments

Comments
 (0)
Please sign in to comment.