32
32
import org .elasticsearch .action .search .SearchResponse ;
33
33
import org .elasticsearch .common .unit .TimeValue ;
34
34
import org .elasticsearch .index .query .MoreLikeThisQueryBuilder ;
35
+ import org .elasticsearch .search .suggest .SuggestBuilder ;
35
36
import org .springframework .beans .BeansException ;
36
37
import org .springframework .context .ApplicationContext ;
37
38
import org .springframework .context .ApplicationContextAware ;
48
49
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentProperty ;
49
50
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
50
51
import org .springframework .data .elasticsearch .core .mapping .SimpleElasticsearchMappingContext ;
52
+ import org .springframework .data .elasticsearch .core .query .BulkOptions ;
51
53
import org .springframework .data .elasticsearch .core .query .GetQuery ;
52
54
import org .springframework .data .elasticsearch .core .query .IndexQuery ;
53
55
import org .springframework .data .elasticsearch .core .query .IndexQueryBuilder ;
54
56
import org .springframework .data .elasticsearch .core .query .MoreLikeThisQuery ;
55
57
import org .springframework .data .elasticsearch .core .query .NativeSearchQueryBuilder ;
56
58
import org .springframework .data .elasticsearch .core .query .Query ;
57
59
import org .springframework .data .elasticsearch .core .query .SeqNoPrimaryTerm ;
60
+ import org .springframework .data .elasticsearch .core .query .UpdateQuery ;
58
61
import org .springframework .data .elasticsearch .support .VersionInfo ;
59
62
import org .springframework .data .mapping .callback .EntityCallbacks ;
60
63
import org .springframework .data .util .CloseableIterator ;
@@ -199,6 +202,11 @@ public <T> T get(GetQuery query, Class<T> clazz, IndexCoordinates index) {
199
202
return get (query .getId (), clazz , index );
200
203
}
201
204
205
+ @ Override
206
+ public <T > List <T > multiGet (Query query , Class <T > clazz ) {
207
+ return multiGet (query , clazz , getIndexCoordinatesFor (clazz ));
208
+ }
209
+
202
210
@ Override
203
211
@ Nullable
204
212
public <T > T queryForObject (GetQuery query , Class <T > clazz ) {
@@ -226,6 +234,11 @@ public String delete(String id, Class<?> entityType) {
226
234
return this .delete (id , getIndexCoordinatesFor (entityType ));
227
235
}
228
236
237
+ @ Override
238
+ public void delete (Query query , Class <?> clazz ) {
239
+ delete (query , getIndexCoordinatesFor (clazz ));
240
+ }
241
+
229
242
@ Override
230
243
public String delete (Object entity ) {
231
244
return delete (entity , getIndexCoordinatesFor (entity .getClass ()));
@@ -235,6 +248,22 @@ public String delete(Object entity) {
235
248
public String delete (Object entity , IndexCoordinates index ) {
236
249
return this .delete (getEntityId (entity ), index );
237
250
}
251
+
252
+ @ Override
253
+ public List <String > bulkIndex (List <IndexQuery > queries , Class <?> clazz ) {
254
+ return bulkIndex (queries , getIndexCoordinatesFor (clazz ));
255
+ }
256
+
257
+ @ Override
258
+ public List <String > bulkIndex (List <IndexQuery > queries , BulkOptions bulkOptions , Class <?> clazz ) {
259
+ return bulkIndex (queries , bulkOptions , getIndexCoordinatesFor (clazz ));
260
+ }
261
+
262
+ @ Override
263
+ public void bulkUpdate (List <UpdateQuery > queries , Class <?> clazz ) {
264
+ bulkUpdate (queries , getIndexCoordinatesFor (clazz ));
265
+ }
266
+
238
267
// endregion
239
268
240
269
// region SearchOperations
@@ -282,6 +311,11 @@ public <T> SearchHits<T> search(MoreLikeThisQuery query, Class<T> clazz, IndexCo
282
311
return search (new NativeSearchQueryBuilder ().withQuery (moreLikeThisQueryBuilder ).build (), clazz , index );
283
312
}
284
313
314
+ @ Override
315
+ public <T > List <SearchHits <T >> multiSearch (List <? extends Query > queries , Class <T > clazz ) {
316
+ return multiSearch (queries , clazz , getIndexCoordinatesFor (clazz ));
317
+ }
318
+
285
319
@ Override
286
320
public <T > List <SearchHits <T >> multiSearch (List <? extends Query > queries , Class <T > clazz , IndexCoordinates index ) {
287
321
MultiSearchRequest request = new MultiSearchRequest ();
@@ -300,9 +334,46 @@ public <T> List<SearchHits<T>> multiSearch(List<? extends Query> queries, Class<
300
334
return res ;
301
335
}
302
336
337
+ @ Override
338
+ public List <SearchHits <?>> multiSearch (List <? extends Query > queries , List <Class <?>> classes ) {
339
+
340
+ Assert .notNull (queries , "queries must not be null" );
341
+ Assert .notNull (classes , "classes must not be null" );
342
+ Assert .isTrue (queries .size () == classes .size (), "queries and classes must have the same size" );
343
+
344
+ MultiSearchRequest request = new MultiSearchRequest ();
345
+ Iterator <Class <?>> it = classes .iterator ();
346
+ for (Query query : queries ) {
347
+ Class <?> clazz = it .next ();
348
+ request .add (requestFactory .searchRequest (query , clazz , getIndexCoordinatesFor (clazz )));
349
+ }
350
+
351
+ MultiSearchResponse .Item [] items = getMultiSearchResult (request );
352
+
353
+ List <SearchHits <?>> res = new ArrayList <>(queries .size ());
354
+ int c = 0 ;
355
+ Iterator <Class <?>> it1 = classes .iterator ();
356
+ for (Query query : queries ) {
357
+ Class entityClass = it1 .next ();
358
+
359
+ SearchDocumentResponseCallback <SearchHits <?>> callback = new ReadSearchDocumentResponseCallback <>(entityClass ,
360
+ getIndexCoordinatesFor (entityClass ));
361
+
362
+ SearchResponse response = items [c ++].getResponse ();
363
+ res .add (callback .doWith (SearchDocumentResponse .from (response )));
364
+ }
365
+ return res ;
366
+ }
367
+
303
368
@ Override
304
369
public List <SearchHits <?>> multiSearch (List <? extends Query > queries , List <Class <?>> classes ,
305
370
IndexCoordinates index ) {
371
+
372
+ Assert .notNull (queries , "queries must not be null" );
373
+ Assert .notNull (classes , "classes must not be null" );
374
+ Assert .notNull (index , "index must not be null" );
375
+ Assert .isTrue (queries .size () == classes .size (), "queries and classes must have the same size" );
376
+
306
377
MultiSearchRequest request = new MultiSearchRequest ();
307
378
Iterator <Class <?>> it = classes .iterator ();
308
379
for (Query query : queries ) {
@@ -356,6 +427,12 @@ protected void searchScrollClear(String scrollId) {
356
427
abstract protected void searchScrollClear (List <String > scrollIds );
357
428
358
429
abstract protected MultiSearchResponse .Item [] getMultiSearchResult (MultiSearchRequest request );
430
+
431
+ @ Override
432
+ public SearchResponse suggest (SuggestBuilder suggestion , Class <?> clazz ) {
433
+ return suggest (suggestion , getIndexCoordinatesFor (clazz ));
434
+ }
435
+
359
436
// endregion
360
437
361
438
// region Helper methods
0 commit comments