Jest客户端/ ElasticSearch集群信息

时间:2016-08-01 08:27:53

标签: java elasticsearch jest

我在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"
}

1 个答案:

答案 0 :(得分: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 <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);
        }
    }
}

你完全按照自己的意愿进入控制台