玩笑客户端/ ElasticSearch集群信息
问题描述:
我用开玩笑的客户端在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"
}
答
我花了一点时间阅读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欢迎您! –
难道页面卷曲-XGET'http:// localhost:9200 /?漂亮'? –
是的,当运行ElasticSearch –
恐怕你不能通过jest/java api完成这项工作。你能解释你的用例这个信息吗? –