简体   繁体   English

Jest 客户端/ ElasticSearch 集群信息

[英]Jest client/ ElasticSearch cluster informations

I'm using jest client in a java application to connect to an ElasticSearch cluster and now i want to find informations on how to get cluster informations like this with jest api:我在 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"
}

I've spent a little time in reading jest source code and get a result.我花了一点时间阅读 jest 源代码并得到结果。 Please look at the code below:请看下面的代码:

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);
        }

    }
}

and GetStartPage.javaGetStartPage.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);
        }
    }
}

You get in console exactly what you wanted你得到了你想要的控制台

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM