8
8
import com .fasterxml .jackson .core .type .TypeReference ;
9
9
import com .fasterxml .jackson .databind .ObjectMapper ;
10
10
import org .apache .http .util .EntityUtils ;
11
+ import org .elasticsearch .client .RestHighLevelClient ;
11
12
import org .elasticsearch .client .indices .CreateIndexRequest ;
12
13
import org .elasticsearch .client .indices .CreateIndexResponse ;
13
14
import org .elasticsearch .client .indices .GetIndexRequest ;
21
22
import org .elasticsearch .cluster .metadata .MappingMetadata ;
22
23
import org .elasticsearch .common .settings .Settings ;
23
24
import org .elasticsearch .common .xcontent .XContentType ;
24
- import org .springframework .data .elasticsearch .core .ElasticsearchRestTemplate ;
25
25
import org .springframework .stereotype .Service ;
26
26
27
27
import java .io .IOException ;
40
40
public class IndexServiceImpl implements IIndexService {
41
41
private ObjectMapper mapper = new ObjectMapper ();
42
42
43
- private final ElasticsearchRestTemplate elasticsearchRestTemplate ;
43
+ private final RestHighLevelClient client ;
44
44
45
- public IndexServiceImpl (ElasticsearchRestTemplate elasticsearchRestTemplate ) {
46
- this .elasticsearchRestTemplate = elasticsearchRestTemplate ;
45
+ public IndexServiceImpl (RestHighLevelClient client ) {
46
+ this .client = client ;
47
47
}
48
48
49
49
@ Override
@@ -57,7 +57,7 @@ public boolean create(IndexDto indexDto) throws IOException {
57
57
//mappings
58
58
request .mapping (indexDto .getMappingsSource (), XContentType .JSON );
59
59
}
60
- CreateIndexResponse response = elasticsearchRestTemplate . getClient ()
60
+ CreateIndexResponse response = client
61
61
.indices ()
62
62
.create (request , RequestOptions .DEFAULT );
63
63
return response .isAcknowledged ();
@@ -66,7 +66,7 @@ public boolean create(IndexDto indexDto) throws IOException {
66
66
@ Override
67
67
public boolean delete (String indexName ) throws IOException {
68
68
DeleteIndexRequest request = new DeleteIndexRequest (indexName );
69
- AcknowledgedResponse response = elasticsearchRestTemplate . getClient () .indices ().delete (request , RequestOptions .DEFAULT );
69
+ AcknowledgedResponse response = client .indices ().delete (request , RequestOptions .DEFAULT );
70
70
return response .isAcknowledged ();
71
71
}
72
72
@@ -75,7 +75,7 @@ public PageResult<Map<String, String>> list(String queryStr, String indices) thr
75
75
if (StrUtil .isNotEmpty (queryStr )) {
76
76
indices = queryStr ;
77
77
}
78
- Response response = elasticsearchRestTemplate . getClient () .getLowLevelClient ()
78
+ Response response = client .getLowLevelClient ()
79
79
.performRequest (new Request (
80
80
"GET" ,
81
81
"/_cat/indices?h=health,status,index,docsCount,docsDeleted,storeSize&s=cds:desc&format=json&index=" +StrUtil .nullToEmpty (indices )
@@ -93,7 +93,7 @@ public PageResult<Map<String, String>> list(String queryStr, String indices) thr
93
93
@ Override
94
94
public Map <String , Object > show (String indexName ) throws IOException {
95
95
GetIndexRequest request = new GetIndexRequest (indexName );
96
- GetIndexResponse getIndexResponse = elasticsearchRestTemplate . getClient ()
96
+ GetIndexResponse getIndexResponse = client
97
97
.indices ().get (request , RequestOptions .DEFAULT );
98
98
MappingMetadata mappingMetadata = getIndexResponse .getMappings ().get (indexName );
99
99
Map <String , Object > mappOpenMap = mappingMetadata .getSourceAsMap ();
0 commit comments