![](/img/trans.png)
[英]Update data stored in ElasticSearch in Java with TransportClient
[英]Spring Data ElasticSearch TransportClient Java Config
有人知道什么是Java Config相當於:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/data/elasticsearch
http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd">
<elasticsearch:transport-client id="client" cluster-nodes="localhost:9300,someip:9300"
/>
</beans>
我特別想使用nodeBuilder()
來做到這一點。
查看ElasticSearch的Spring Data文檔:
@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存儲庫 2.1.2基於注釋的配置
Spring Data Elasticsearch存儲庫支持不僅可以通過XML命名空間激活,還可以通過JavaConfig使用注釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.