About the spring - data - elasticsearch:
When using ElasticsearchTemplate, you are using the TransportClient.
When using ElasticsearchRestTemplate you are using the RestClient (available in 3.2.0).
When using a default ElasticsearchRepository you are using the TransportClient.
When using a custom repository extending for example SimpleElasticsearchRepository like to you are using the RestClient.
To solve the main problem
1, the TransportClient is replaced by the RestClient
2, replace ElasticsearchTemplate ElasticsearchRestTemplate;
A, pom. XML change
-->
Org. Springframework. Boot -->
Spring - the boot - starter - data - elasticsearch -->
-->
The original spring - the boot - starter - data - elasticsearch modification for spring - data - elasticsearch, as a result of our es is 6.8.1 version, I will be the corresponding some client jar version also replaced with 6.8.1 version,
Two, start the class add @ EnableElasticsearchRepositories
@ EnableElasticsearchRepositories
Public class DocServerApplication {
Public static void main (String [] args) {
Ty System. SetProperty (" es.set.net. Runtime. The available. Processors ", "false");
SpringApplication. Run (DocServerApplication. Class, args);
}
}
Three application. Yml increased es configuration
Es:
Cluster:
Name: my - application
User: elastic
Password: elastic
Url: 192.168.170.31
Port: 9200
Four, the project will inject ES ElasticsearchRestTemplate appointed elasticsearchTemplate, support the original function of jpa
The import org. Apache. HTTP. HttpHost;
The import org. Apache. HTTP. Auth. AuthScope;
The import org. Apache. HTTP. Auth. UsernamePasswordCredentials;
The import org. Apache. HTTP. Client. CredentialsProvider;
The import org. Apache. HTTP. Impl. Client. BasicCredentialsProvider;
The import org. Apache. HTTP. Impl. Nio. Client. HttpAsyncClientBuilder;
The import org. Elasticsearch. Client. RestClient;
The import org. Elasticsearch. Client. RestClientBuilder;
The import org. Elasticsearch. Client. RestHighLevelClient;
The import org. Springframework. Beans. Factory. The annotation. The Qualifier;
Import org. Springframework. Beans. Factory. The annotation, the Value;
The import org. Springframework. Boot. Autoconfigure. Condition. ConditionalOnClass;
The import org. Springframework. Context. The annotation. Bean;
The import org. Springframework. Context. The annotation. The Configuration;
The import org. Springframework. Data. Elasticsearch. Config. AbstractElasticsearchConfiguration;
The import org. Springframework. Data. Elasticsearch. Core. ElasticsearchRestTemplate;
The import javax.mail. The annotation. PostConstruct;
/* *
* project inject ES
*/
@ Configuration
@ ConditionalOnClass (RestHighLevelClient. Class)
Public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
@ PostConstruct
Void init () {
Ty System. SetProperty (" es.set.net. Runtime. The available. Processors ", "false");
}
@ Value (" ${es. Cluster. Name: # {null}} ")
private String name;
@ Value (" ${es. User: # {null}} ")
Private String user;
@ Value (" ${es. Password: # {null}} ")
private String password;
@ Value (" ${es. Url: # {null}} ")
Private String url;
@ Value (" ${es. Port: # {null}} ")
Private int port;
@ Override
@ Bean (" restHighLevelClient ")
Public RestHighLevelClient elasticsearchClient () {
Final CredentialsProvider CredentialsProvider=new BasicCredentialsProvider ();
/* set the password */
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull