Spring Data ElasticSearch TransportClient Java Config
Take a look into Spring Data documentations for ElasticSearch:
@Configuration @EnableElasticsearchRepositories(basePackages = "org/springframework/data/elasticsearch/repositories") static class Config { @Value("${esearch.port}") int port; @Value("${esearch.host}") String hostname; @Bean public ElasticsearchOperations elasticsearchTemplate() { return new ElasticsearchTemplate(client()); } @Bean public Client client(){ TransportClient client= new TransportClient(); TransportAddress address = new InetSocketTransportAddress(hostname, port); client.addTransportAddress(address); return client; } }
Elasticsearch Repositories 2.1.2 Annotation based configuration
The Spring Data Elasticsearch repositories support cannot only be activated through an XML namespace but also using an annotation through JavaConfig.