2014-11-21 15 views
7

किसी को भी पता है क्या के जावा कॉन्फ़िग बराबर है:स्प्रिंग डाटा ElasticSearch TransportClient जावा कॉन्फ़िग

<?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() उपयोग करने के लिए यह करना चाहते हैं।

उत्तर

11

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 एनोटेशन आधारित विन्यास

स्प्रिंग डाटा Elasticsearch खजाने समर्थन केवल एक एक्सएमएल के माध्यम से सक्रिय नहीं किया जा सकता नेमस्पेस लेकिन JavaConfig के माध्यम से एक एनोटेशन का उपयोग भी कर रहा है।

+0

कोड के ऊपर एक परिवहन क्लाइंट के बजाय का निर्माण नहीं करता है कि यह एक नोड ग्राहक बनाता है और एक्सएमएल विन्यास निम्नलिखित के जावा कॉन्फ़िग बराबर है

+0

कृपया ट्रांसपोर्ट क्लाइंट के साथ अपडेट देखें, जहां आप उस कन्स्ट्रक्टर –

+2

के साथ ElasticsearchTemplate को कॉल कर सकते हैं, आप सेटिंग सेटिंग्स = ImmutableSettings.settingsBuilder() को पास कर सकते हैं। ("", "")।() "(" "," ")।() को ट्रांसफर क्लाइंट के कन्स्ट्रक्टर को कॉन्फ़िगर करने के लिए ... –

संबंधित मुद्दे