Jest 客户端/ ElasticSearch 集群信息
Jest client/ ElasticSearch cluster informations
我在 java 应用程序中使用 jest 客户端连接到 ElasticSearch 集群,现在我想查找有关如何使用 jest api 获取集群信息的信息:
{
"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 <vladislav.kisliy@gmail.com>
*/
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);
}
}
}
您在控制台中得到的正是您想要的
我在 java 应用程序中使用 jest 客户端连接到 ElasticSearch 集群,现在我想查找有关如何使用 jest api 获取集群信息的信息:
{
"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 <vladislav.kisliy@gmail.com>
*/
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);
}
}
}
您在控制台中得到的正是您想要的