Package tutorial.storm.trident.example.elasticsearch

Source Code of tutorial.storm.trident.example.elasticsearch.ElasticSearchSingleton

package tutorial.storm.trident.example.elasticsearch;

import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;

import static org.elasticsearch.node.NodeBuilder.nodeBuilder;

/**
* @author Davide Palmisano (davide.palmisano@peerindex.com)
*/
public class ElasticSearchSingleton {

    private static final Client INSTANCE = getInstance();

    public static Client getInstance() {
            Node node = nodeBuilder().node();
            Client client = node.client();
            createIndex(INSTANCE);
            return client;
    }

    private static void createIndex(Client client) {
        boolean exist = client.admin().indices().prepareExists("hackaton").execute().actionGet().isExists();
        if (!exist) {
            client.admin().indices().prepareCreate("hackaton").execute().actionGet();
        }
    }

}
TOP

Related Classes of tutorial.storm.trident.example.elasticsearch.ElasticSearchSingleton

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.