2016-08-01 150 views
3

我用開玩笑的客戶端在Java應用程序連接到ElasticSearch集羣,現在我想找到如何讓集羣信息像這樣與笑話API的信息:玩笑客戶端/ ElasticSearch集羣信息

{ 
"name" : "", 
"cluster_name" : "", 
"version" : { 
"number" : "2.3.2", 
"build_hash" : "", 
"build_timestamp" : "", 
"build_snapshot" : , 
"lucene_version" : " 
}, 
"tagline" : "You Know, for Search" 
} 
+0

難道頁面捲曲-XGET'http:// localhost:9200 /?漂亮'? –

+0

是的,當運行ElasticSearch –

+0

恐怕你不能通過jest/java api完成這項工作。你能解釋你的用例這個信息嗎? –

回答

2

我花了一點時間閱讀jest源代碼並獲得結果。請看下面的代碼:

Jest.java

import io.searchbox.client.JestClient; 
import io.searchbox.client.JestClientFactory; 
import io.searchbox.client.JestResult; 
import io.searchbox.client.config.HttpClientConfig; 
import java.io.IOException; 
import java.util.logging.Level; 
import java.util.logging.Logger; 

/** 
* 
* @author Vladislav Kislyi <[email protected]> 
*/ 
public class Jest { 

    public static void main(String[] args) throws IOException { 
     // Construct a new Jest client according to configuration via factory 
     JestClientFactory factory = new JestClientFactory(); 
     factory.setHttpClientConfig(new HttpClientConfig.Builder("http://localhost:9200") 
       .multiThreaded(true) 
       .build()); 
     JestClient client = factory.getObject(); 

     GetStartPage getStartPage = new GetStartPage.Builder().build(); 
     try { 
      JestResult execute = client.execute(getStartPage); 
      System.out.println("result =" + execute.getJsonString()); 
     } catch (IOException ex) { 
      Logger.getLogger(Jest.class.getName()).log(Level.SEVERE, null, ex); 
     } 

    } 
} 

GetStartPage.java

import io.searchbox.action.AbstractAction; 
import io.searchbox.action.GenericResultAbstractAction; 

public class GetStartPage extends GenericResultAbstractAction { 

    protected GetStartPage(Builder builder) { 
     super(builder); 
     setURI(buildURI()); 
    } 

    protected String buildURI() { 
     return super.buildURI() + "/?pretty"; 
    } 

    @Override 
    public String getRestMethodName() { 
     return "GET"; 
    } 

    public static class Builder extends AbstractAction.Builder<GetStartPage, Builder> { 

     @Override 
     public GetStartPage build() { 
      return new GetStartPage(this); 
     } 
    } 
} 

你得到的控制檯,您想要什麼

+0

我得到了我想要的東西,謝謝 –

+0

@MeriemRezgui歡迎您! –