22
22
import org .springframework .beans .factory .annotation .Value ;
23
23
import org .springframework .cache .CacheManager ;
24
24
import org .springframework .cache .annotation .Cacheable ;
25
- import org .springframework .cache .annotation .EnableCaching ;
26
25
import org .springframework .context .ApplicationContext ;
27
26
import org .springframework .data .annotation .Id ;
28
27
import org .springframework .data .elasticsearch .annotations .Setting ;
@@ -64,9 +63,6 @@ public class ElasticIndexService implements IElasticIndexService {
64
63
@ Autowired
65
64
private ApplicationContext context ;
66
65
67
- @ Autowired
68
- private ElasticsearchRestTemplate elasticsearchTemplate ;
69
-
70
66
@ Autowired
71
67
private ElasticsearchOperations operations ;
72
68
@@ -170,7 +166,7 @@ public String getIndexByMenuItemId(String menuItemId) {
170
166
@ Override
171
167
public boolean indexExists (String indexName ) {
172
168
try {
173
- return elasticsearchTemplate .indexOps (IndexCoordinates .of (indexName )).exists ();
169
+ return template .indexOps (IndexCoordinates .of (indexName )).exists ();
174
170
} catch (Exception e ) {
175
171
log .error ("indexExists:" , e );
176
172
return false ;
@@ -180,7 +176,7 @@ public boolean indexExists(String indexName) {
180
176
@ Override
181
177
public <T > String index (Class <T > clazz , T source , String ... placeholders ) {
182
178
String indexName = getIndexName (clazz , placeholders );
183
- return elasticsearchTemplate .index (new IndexQueryBuilder ().withId (getIdFromSource (source ))
179
+ return template .index (new IndexQueryBuilder ().withId (getIdFromSource (source ))
184
180
.withObject (source ).build (), IndexCoordinates .of (indexName ));
185
181
}
186
182
@@ -266,7 +262,7 @@ public boolean deleteIndex(Class<?> clazz, String... placeholders) {
266
262
String indexName = getIndexName (clazz , placeholders );
267
263
if (this .indexExists (indexName )) {
268
264
log .warn ("Index: " + indexName + " has been deleted!" );
269
- return elasticsearchTemplate .indexOps (IndexCoordinates .of (indexName )).delete ();
265
+ return template .indexOps (IndexCoordinates .of (indexName )).delete ();
270
266
} else {
271
267
log .warn ("Index: " + indexName + " not found!" );
272
268
}
@@ -281,7 +277,7 @@ public boolean openIndex(Class<?> clazz, String... placeholders) {
281
277
try {
282
278
String indexName = getIndexName (clazz , placeholders );
283
279
OpenIndexRequest request = new OpenIndexRequest (indexName );
284
- OpenIndexResponse execute = elasticsearchTemplate .execute (client -> client .indices ().open (request , RequestOptions .DEFAULT ));
280
+ OpenIndexResponse execute = template .execute (client -> client .indices ().open (request , RequestOptions .DEFAULT ));
285
281
boolean acknowledged = execute .isAcknowledged ();
286
282
if (acknowledged ) {
287
283
log .info ("Open index {} success" , indexName );
@@ -300,7 +296,7 @@ public boolean closeIndex(Class<?> clazz, String... placeholders) {
300
296
try {
301
297
String indexName = getIndexName (clazz , placeholders );
302
298
CloseIndexRequest request = new CloseIndexRequest (indexName );
303
- CloseIndexResponse execute = elasticsearchTemplate .execute (client -> client .indices ().close (request , RequestOptions .DEFAULT ));
299
+ CloseIndexResponse execute = template .execute (client -> client .indices ().close (request , RequestOptions .DEFAULT ));
304
300
boolean acknowledged = execute .isAcknowledged ();
305
301
if (acknowledged ) {
306
302
log .info ("Close index {} success" , indexName );
@@ -318,7 +314,7 @@ public boolean closeIndex(Class<?> clazz, String... placeholders) {
318
314
public SearchHits <?> search (Query query , Class <?> clazz , String ... placeholders ) {
319
315
try {
320
316
String indexName = getIndexName (clazz , placeholders );
321
- return elasticsearchTemplate .search (query , clazz , IndexCoordinates .of (indexName ));
317
+ return template .search (query , clazz , IndexCoordinates .of (indexName ));
322
318
} catch (Exception e ) {
323
319
log .error ("scrollFirst:" , e );
324
320
}
@@ -346,7 +342,7 @@ public boolean putMapping(Class<?> clazz, String... placeholders) {
346
342
try {
347
343
String indexName = getIndexName (clazz , placeholders );
348
344
Document mapping = operations .indexOps (clazz ).createMapping ();
349
- return elasticsearchTemplate .indexOps (IndexCoordinates .of (indexName )).putMapping (mapping );
345
+ return template .indexOps (IndexCoordinates .of (indexName )).putMapping (mapping );
350
346
} catch (Exception e ) {
351
347
log .error ("deleteIndex:" , e );
352
348
return false ;
@@ -359,7 +355,7 @@ public boolean putTemplate(String name, String source) {
359
355
try {
360
356
PutIndexTemplateRequest builder = new PutIndexTemplateRequest (name );
361
357
builder .source (source , XContentType .JSON );
362
- AcknowledgedResponse execute = elasticsearchTemplate .execute (client -> client .indices ().putTemplate (builder , RequestOptions .DEFAULT ));
358
+ AcknowledgedResponse execute = template .execute (client -> client .indices ().putTemplate (builder , RequestOptions .DEFAULT ));
363
359
return execute .isAcknowledged ();
364
360
} catch (Exception e ) {
365
361
log .error ("putTemplate:" , e );
@@ -371,7 +367,7 @@ public boolean putTemplate(String name, String source) {
371
367
public SearchScrollHits <?> scrollFirst (Query query , Class <?> clazz , String ... placeholders ) {
372
368
String indexName = getIndexName (clazz , placeholders );
373
369
try {
374
- return elasticsearchTemplate .searchScrollStart (60000 , query , clazz , IndexCoordinates .of (indexName ));
370
+ return template .searchScrollStart (60000 , query , clazz , IndexCoordinates .of (indexName ));
375
371
} catch (Exception e ) {
376
372
log .error ("scrollFirst: " , e );
377
373
}
@@ -382,7 +378,7 @@ public SearchScrollHits<?> scrollFirst(Query query, Class<?> clazz, String... pl
382
378
public SearchScrollHits <?> scroll (String scrollId , Class <?> clazz , String ... placeholders ) {
383
379
String indexName = getIndexName (clazz , placeholders );
384
380
try {
385
- return elasticsearchTemplate .searchScrollContinue (scrollId , 60000 , clazz , IndexCoordinates .of (indexName ));
381
+ return template .searchScrollContinue (scrollId , 60000 , clazz , IndexCoordinates .of (indexName ));
386
382
} catch (Exception e ) {
387
383
log .error ("scrollFirst:" , e );
388
384
}
@@ -461,6 +457,4 @@ private String getIndexName(Class<?> clazz, String... placeholders) {
461
457
}
462
458
return indexName ;
463
459
}
464
-
465
- }
466
-
460
+ }
0 commit comments