Search in sources :

Example 1 with ElasticSearchClusterConfiguration

use of org.qi4j.index.elasticsearch.ElasticSearchClusterConfiguration in project qi4j-sdk by Qi4j.

the class ESClusterSupport method activateElasticSearch.

@Override
protected void activateElasticSearch() throws Exception {
    configuration.refresh();
    ElasticSearchClusterConfiguration config = configuration.get();
    String clusterName = config.clusterName().get() == null ? DEFAULT_CLUSTER_NAME : config.clusterName().get();
    index = config.index().get() == null ? DEFAULT_INDEX_NAME : config.index().get();
    indexNonAggregatedAssociations = config.indexNonAggregatedAssociations().get();
    String[] nodes = config.nodes().get() == null ? new String[] { "localhost:9300" } : config.nodes().get().split(",");
    boolean clusterSniff = config.clusterSniff().get();
    boolean ignoreClusterName = config.ignoreClusterName().get();
    String pingTimeout = config.pingTimeout().get() == null ? "5s" : config.pingTimeout().get();
    String samplerInterval = config.samplerInterval().get() == null ? "5s" : config.samplerInterval().get();
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).put("client.transport.sniff", clusterSniff).put("client.transport.ignore_cluster_name", ignoreClusterName).put("client.transport.ping_timeout", pingTimeout).put("client.transport.nodes_sampler_interval", samplerInterval).build();
    TransportClient transportClient = new TransportClient(settings);
    for (String node : nodes) {
        String[] split = node.split(":");
        String host = split[0];
        int port = Integer.valueOf(split[1]);
        transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
    }
    client = transportClient;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) ElasticSearchClusterConfiguration(org.qi4j.index.elasticsearch.ElasticSearchClusterConfiguration) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings)

Aggregations

TransportClient (org.elasticsearch.client.transport.TransportClient)1 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)1 Settings (org.elasticsearch.common.settings.Settings)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 ElasticSearchClusterConfiguration (org.qi4j.index.elasticsearch.ElasticSearchClusterConfiguration)1