Search in sources :

Example 31 with PreBuiltTransportClient

use of org.elasticsearch.transport.client.PreBuiltTransportClient in project incubator-skywalking by apache.

the class ElasticSearchClient method initialize.

@Override
public void initialize() throws ClientException {
    Settings settings = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", clusterTransportSniffer).build();
    client = new PreBuiltTransportClient(settings);
    List<AddressPairs> pairsList = parseClusterNodes(clusterNodes);
    for (AddressPairs pairs : pairsList) {
        try {
            ((PreBuiltTransportClient) client).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(pairs.host), pairs.port));
        } catch (UnknownHostException e) {
            throw new ElasticSearchClientException(e.getMessage(), e);
        }
    }
    this.ready = true;
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) UnknownHostException(java.net.UnknownHostException) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 32 with PreBuiltTransportClient

use of org.elasticsearch.transport.client.PreBuiltTransportClient in project topcom-cloud by 545314690.

the class ElasticSearchService method init.

@PostConstruct
public void init() {
    try {
        Settings settings = Settings.builder().put("cluster.name", EsConf.CLUSTER_NAME).build();
        this.client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(EsConf.IP), EsConf.PORT));
    } catch (UnknownHostException e) {
        log.error("es init failed!", e);
    }
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) UnknownHostException(java.net.UnknownHostException) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) PostConstruct(javax.annotation.PostConstruct)

Example 33 with PreBuiltTransportClient

use of org.elasticsearch.transport.client.PreBuiltTransportClient in project vertigo by KleeGroup.

the class ESTransportSearchServicesPlugin method createClient.

/**
 * {@inheritDoc}
 */
@Override
protected Client createClient() {
    client = new PreBuiltTransportClient(buildNodeSettings());
    for (final String serverName : serversNames) {
        final String[] serverNameSplit = serverName.split(":");
        Assertion.checkArgument(serverNameSplit.length == 2, "La dĂ©claration du serveur doit ĂȘtre au format host:port ({0}", serverName);
        final int port = Integer.parseInt(serverNameSplit[1]);
        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(serverNameSplit[0], port)));
    }
    return client;
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) InetSocketAddress(java.net.InetSocketAddress) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 34 with PreBuiltTransportClient

use of org.elasticsearch.transport.client.PreBuiltTransportClient in project fess-crawler by codelibs.

the class EsClient method createTransportClient.

protected TransportClient createTransportClient() {
    final Settings settings = Settings.builder().put("cluster.name", StringUtil.isBlank(clusterName) ? "elasticsearch" : clusterName).build();
    final TransportClient transportClient = new PreBuiltTransportClient(settings);
    Arrays.stream(addresses).forEach(address -> {
        final String[] values = address.split(":");
        String hostname;
        int port = 9300;
        if (values.length == 1) {
            hostname = values[0];
        } else if (values.length == 2) {
            hostname = values[0];
            port = Integer.parseInt(values[1]);
        } else {
            throw new CrawlerSystemException("Invalid address: " + address);
        }
        try {
            transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(hostname), port));
        } catch (final Exception e) {
            throw new CrawlerSystemException("Unknown host: " + address);
        }
        logger.info("Connected to " + hostname + ":" + port);
    });
    return transportClient;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) CrawlerSystemException(org.codelibs.fess.crawler.exception.CrawlerSystemException) Settings(org.elasticsearch.common.settings.Settings) ElasticsearchException(org.elasticsearch.ElasticsearchException) CrawlerSystemException(org.codelibs.fess.crawler.exception.CrawlerSystemException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) EsAccessException(org.codelibs.fess.crawler.exception.EsAccessException) VersionConflictEngineException(org.elasticsearch.index.engine.VersionConflictEngineException)

Example 35 with PreBuiltTransportClient

use of org.elasticsearch.transport.client.PreBuiltTransportClient in project bibot by alfintech.

the class ElasticPublisher method initialise.

@PostConstruct
public void initialise() throws IOException {
    Settings settings = Settings.builder().put("cluster.name", clusterName).put("node.name", nodeName).build();
    client = new PreBuiltTransportClient(settings);
    client.addTransportAddress(new TransportAddress(InetAddress.getByName(elasticHost), elasticPort));
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Settings(org.elasticsearch.common.settings.Settings) PostConstruct(javax.annotation.PostConstruct)

Aggregations

PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)41 Settings (org.elasticsearch.common.settings.Settings)33 TransportClient (org.elasticsearch.client.transport.TransportClient)25 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)23 TransportAddress (org.elasticsearch.common.transport.TransportAddress)17 UnknownHostException (java.net.UnknownHostException)10 InetSocketAddress (java.net.InetSocketAddress)5 InetAddress (java.net.InetAddress)4 HashMap (java.util.HashMap)4 PostConstruct (javax.annotation.PostConstruct)4 SearchItem (cn.exrick.manager.dto.front.SearchItem)3 IOException (java.io.IOException)3 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)3 IndexResponse (org.elasticsearch.action.index.IndexResponse)3 Builder (org.elasticsearch.common.settings.Settings.Builder)3 XmallException (cn.exrick.common.exception.XmallException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Logger (org.apache.log4j.Logger)2 ElasticsearchClusterRunner (org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner)2