當前位置: 首頁>>代碼示例>>Java>>正文


Java InetSocketTransportAddress類代碼示例

本文整理匯總了Java中org.elasticsearch.common.transport.InetSocketTransportAddress的典型用法代碼示例。如果您正苦於以下問題:Java InetSocketTransportAddress類的具體用法?Java InetSocketTransportAddress怎麽用?Java InetSocketTransportAddress使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InetSocketTransportAddress類屬於org.elasticsearch.common.transport包,在下文中一共展示了InetSocketTransportAddress類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getElasticClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
private TransportClient getElasticClient() {
        try {
            // un-command this, if you have multiple node
//            TransportClient client1 = new PreBuiltTransportClient(Settings.EMPTY)
//                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
//                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300));

            Settings setting = Settings.builder()
                    .put("cluster.name", elasticPro.getProperty("cluster"))
                    .put("client.transport.sniff", Boolean.valueOf(elasticPro.getProperty("transport.sniff"))).build();

            client = new PreBuiltTransportClient(setting)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticPro.getProperty("host")), Integer.valueOf(elasticPro.getProperty("port"))));
        } catch (UnknownHostException ex) {
            log.error("Exception occurred while getting Client : " + ex, ex);
        }
        return client;
    }
 
開發者ID:sundarcse1216,項目名稱:es-crud,代碼行數:19,代碼來源:ElasticSearchClient.java

示例2: createClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
private TransportClient createClient() {
    Config cfg = getTypeCfg();
    Settings settings = Settings.builder().put("cluster.name", cfg.getString("elastic.cluster-name")).build();
    TransportClient client = new PreBuiltTransportClient(settings);

    List<String> servers = cfg.getStringList("elastic.servers");
    logger.debug(marker, "Elastic Servers: {}", servers);
    for (String addr : servers) {
        try {
            String[] a = addr.split(":");
            String host = a[0];
            int port = Integer.parseInt(a[1]);
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
        } catch (Exception e) {
            logger.error(marker, "Transport client creation failed for '{}'", addr, e);
        }
    }

    return client;
}
 
開發者ID:Lambda-3,項目名稱:Stargraph,代碼行數:21,代碼來源:ElasticClient.java

示例3: getClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
public static TransportClient getClient() {
    try {
        if (tclient == null) {
            String EsHosts = "192.168.1.41:9300,192.168.1.42:9300,192.168.1.43:9300";
            Settings settings = Settings.settingsBuilder()
                    .put("cluster.name", "dkes")//設置集群名稱
                    .put("tclient.transport.sniff", true).build();//自動嗅探整個集群的狀態,把集群中其它機器的ip地址加到客戶端中

            tclient = TransportClient.builder().settings(settings).build();
            String[] nodes = EsHosts.split(",");
            for (String node : nodes) {
                if (node.length() > 0) {//跳過為空的node(當開頭、結尾有逗號或多個連續逗號時會出現空node)
                    String[] hostPort = node.split(":");
                    tclient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostPort[0]), Integer.parseInt(hostPort[1])));

                }
            }
        }//if
    } catch (Exception e) {
        e.printStackTrace();
    }
    return tclient;
}
 
開發者ID:hs-web,項目名稱:hsweb-learning,代碼行數:24,代碼來源:EsClient.java

示例4: wildcardQuery

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
/**
 * wildcard查詢/or條件/and條件
 */
public static void wildcardQuery() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.94"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("sqd.es_start");

        // {"query": {"bool": {"must": [{"or": [{"wildcard": {"content": "*oracle*"}},{"wildcard": {"content": "*mysql*"}}]}],"must_not": [],"should": []}},"from": 0, "size": 10, "sort": [],"aggs": {}}
        SearchResponse searchResponse = searchRequestBuilder.
                setQuery(QueryBuilders.boolQuery()
                .must(QueryBuilders.orQuery(QueryBuilders.wildcardQuery("content","*mysql*"),
                        QueryBuilders.wildcardQuery("content","*oracle*")))
                .must(QueryBuilders.termQuery("tbool","false")))
                .setFrom(0).setSize(100).setExplain(true).execute().actionGet();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
        for (int i = 0; i < searchHits.getHits().length; ++i) {
            System.out.println("content is "
                    + searchHits.getHits()[i].getSource().get("content"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:31,代碼來源:SearchES.java

示例5: multisearch

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
/**
 * 多字段查詢
 */
public static void multisearch() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.93"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("service2","clients");
        SearchResponse searchResponse = searchRequestBuilder.
                setQuery(QueryBuilders.boolQuery()
                        .should(QueryBuilders.termQuery("id","5"))
                        .should(QueryBuilders.prefixQuery("content","oracle")))
                .setFrom(0).setSize(100).setExplain(true).execute().actionGet();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:24,代碼來源:SearchES.java

示例6: getClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
public TransportClient getClient()   {
    if (esClient == null) {
        synchronized (this) {
            if (esClient == null) {
                try {
                    //判斷配置
                    Preconditions.checkNotNull(clusterName, "es 服務clusterName未配置");
                    Preconditions.checkNotNull(addresses, "es 服務ip未配置");
                    //Preconditions.checkArgument(esPort > 0, "es 服務服務port未配置");
                    //設置集群的名字
                    Settings settings = Settings.settingsBuilder().put("client.node", true).put("cluster.name", clusterName).put("client.transport.sniff", sniff).build();
                    //Settings settings = Settings.settingsBuilder().put("client.transport.sniff", sniff).build();
                    //創建集群client並添加集群節點地址
                    esClient = TransportClient.builder().settings(settings).build();
                    for (String address : addresses) {
                        String[] inetAddress = address.split(":");
                        esClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(inetAddress[0]), new Integer(inetAddress[1])));
                    }
                  }catch (Exception e){
                     LOGGER.error("客戶端連接初始化異常",e);
                }
            }
        }
    }
    return esClient;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:27,代碼來源:EshClientFactory.java

示例7: ElasticsearchClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
/**
 * create a elasticsearch transport client (remote elasticsearch)
 * @param addresses an array of host:port addresses
 * @param clusterName
 */
public ElasticsearchClient(final String[] addresses, final String clusterName) {
    // create default settings and add cluster name
    Settings.Builder settings = Settings.builder()
            .put("cluster.routing.allocation.enable", "all")
            .put("cluster.routing.allocation.allow_rebalance", "always");
    if (clusterName != null) settings.put("cluster.name", clusterName);
    
    // create a client
    TransportClient tc = new PreBuiltTransportClient(settings.build());

    for (String address: addresses) {
        String a = address.trim();
        int p = a.indexOf(':');
        if (p >= 0) try {
            InetAddress i = InetAddress.getByName(a.substring(0, p));
            int port = Integer.parseInt(a.substring(p + 1));
            tc.addTransportAddress(new InetSocketTransportAddress(i, port));
        } catch (UnknownHostException e) {
            Data.logger.warn("", e);
        }
    }
    this.elasticsearchClient = tc;
}
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:29,代碼來源:ElasticsearchClient.java

示例8: get

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
/**
 * TransportClient provider.
 * @return TransportClient
 */
public TransportClient get() {
  final String hostCsv = configuration.getString(CONFIG_ES_CLUSTER_HOST);
  final List<String> hosts = Splitter.on(",").splitToList(hostCsv);
  Preconditions.checkState(!hosts.isEmpty());

  final TransportClient transportClient = new PreBuiltTransportClient(esSettings());
  final Integer esTransportPort = configuration.getInteger(CONFIG_ES_CLUSTER_PORT, 9300);
  log.info("connect to elastic search {} on port {} ", hostCsv, esTransportPort);

  hosts.forEach(
      host -> transportClient.addTransportAddress(
          new InetSocketTransportAddress(new InetSocketAddress(host, esTransportPort))
      )
  );

  return transportClient;
}
 
開發者ID:email2liyang,項目名稱:grpc-mate,代碼行數:22,代碼來源:TransportClientProvider.java

示例9: connect

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
@Override
public TransportClient connect() {
    Settings settings = Settings.builder()
        .put("cluster.name", "elasticsearch")
        .put("client.transport.sniff", true).build();       
    
    try {
        client = new PreBuiltTransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("event-apptst01.as.it.ubc.ca"), 9300))
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("event-apptst02.as.it.ubc.ca"), 9300));        
    } catch (UnknownHostException uhe) {
        logger.error(uhe.toString());
    }
    
    return client;
}
 
開發者ID:armenak,項目名稱:uDetective,代碼行數:17,代碼來源:ElasticSearchDataSource.java

示例10: jsonquery

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
/**
 * json查詢
 */
public static void jsonquery() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.93"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("service2");
        SearchResponse searchResponse = searchRequestBuilder.setSource("{\n" +
                "\"query\": {\n" +
                "\"bool\": {\n" +
                "\"must\": [\n" +
                "{\n" +
                "\"prefix\": {\n" +
                "\"content\": \"oracle\"\n" +
                "}\n" +
                "}\n" +
                "],\n" +
                "\"must_not\": [ ],\n" +
                "\"should\": [ ]\n" +
                "}\n" +
                "},\n" +
                "\"from\": 0,\n" +
                "\"size\": 10,\n" +
                "\"sort\": [ ],\n" +
                "\"aggs\": { }\n" +
                "}")
                .get();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
        for (int i = 0; i < searchHits.getHits().length; ++i) {
            System.out.println("content is "
                    + searchHits.getHits()[i].getSource().get("content"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:43,代碼來源:SearchES.java

示例11: main

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
    Log4jESLoggerFactory.getRootLogger().setLevel("ERROR");
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "ciphergateway").build();
    //Use one and only one Client in your JVM. It's threadsafe.
    Client client = new TransportClient(settings)
        .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

    Long start = System.currentTimeMillis();
//    exportES(client);
//    deleteES(client);
//    importES(client);
//    searchES(client);
    exportAndDeleteES(client);
    client.close();
    Long end = System.currentTimeMillis();
    System.out.println("用時: " + (end - start) + " ms");
  }
 
開發者ID:MoneZhao,項目名稱:elasticsearch,代碼行數:18,代碼來源:App.java

示例12: ElasticSearchConnection

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
public ElasticSearchConnection(String jdbcUrl) {


        Settings settings = Settings.builder().put("client.transport.ignore_cluster_name", true).build();
        try {
            TransportClient transportClient = new PreBuiltTransportClient(settings);

            String hostAndPortArrayStr = jdbcUrl.split("/")[2];
            String[] hostAndPortArray = hostAndPortArrayStr.split(",");

            for (String hostAndPort : hostAndPortArray) {
                String host = hostAndPort.split(":")[0];
                String port = hostAndPort.split(":")[1];
                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), Integer.parseInt(port)));
            }
            client = transportClient;
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:mazhou,項目名稱:es-sql,代碼行數:21,代碼來源:ElasticSearchConnection.java

示例13: build

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
/**
 * Builds the {@link MaprElasticSearchService} according to the specified properties.
 *
 * @return instence of {@link MaprElasticSearchService}, which can be started via {@link MaprElasticSearchService#start()}.
 * @throws IllegalStateException in case when some of the required properties are missed.
 */
public MaprElasticSearchService build() {

    ensureFieldNonNull("port", this.port);
    ensureFieldNonNull("hostname", this.inetAddress);
    ensureFieldNonNull("indexName", this.indexName);
    ensureFieldNonNull("typeName", this.typeName);
    ensureFieldNonNull("changelog", this.changelog);
    ensureFieldNonNull("fields", this.fields);

    return () -> {

        // Create ES Client
        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new InetSocketTransportAddress(inetAddress, port));

        // Create CDC Listener
        ChangelogListener listener = ChangelogListenerImpl.forChangelog(changelog);

        // Set 'onInsert' callback
        listener.onInsert(new SaveIndexCDCCallback(client));

        // Set 'onUpdate' callback
        listener.onUpdate(new SaveIndexCDCCallback(client));

        // Define and set 'onDelete' callback
        listener.onDelete((id) -> client.prepareDelete(indexName, typeName, id).get());

        listener.listen();

    };
}
 
開發者ID:mapr-demos,項目名稱:mapr-music,代碼行數:38,代碼來源:MaprElasticSearchServiceBuilder.java

示例14: createTransportClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
private static TransportClient createTransportClient(ElasticsearchSearchIndexConfiguration config) {
    Settings settings = tryReadSettingsFromFile(config);
    if (settings == null) {
        Settings.Builder settingsBuilder = Settings.builder();
        if (config.getClusterName() != null) {
            settingsBuilder.put("cluster.name", config.getClusterName());
        }
        for (Map.Entry<String, String> esSetting : config.getEsSettings().entrySet()) {
            settingsBuilder.put(esSetting.getKey(), esSetting.getValue());
        }
        settings = settingsBuilder.build();
    }
    TransportClient transportClient = new PreBuiltTransportClient(settings);
    for (String esLocation : config.getEsLocations()) {
        String[] locationSocket = esLocation.split(":");
        String hostname;
        int port;
        if (locationSocket.length == 2) {
            hostname = locationSocket[0];
            port = Integer.parseInt(locationSocket[1]);
        } else if (locationSocket.length == 1) {
            hostname = locationSocket[0];
            port = config.getPort();
        } else {
            throw new MemgraphException("Invalid elastic search location: " + esLocation);
        }
        InetAddress host;
        try {
            host = InetAddress.getByName(hostname);
        } catch (UnknownHostException ex) {
            throw new MemgraphException("Could not resolve host: " + hostname, ex);
        }
        transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
    }
    return transportClient;
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:37,代碼來源:Elasticsearch5SearchIndex.java

示例15: initESClient

import org.elasticsearch.common.transport.InetSocketTransportAddress; //導入依賴的package包/類
@Bean
public TransportClient initESClient() throws NumberFormatException, UnknownHostException{
	String ip = env.getProperty("spring.es.ip");
	String port = env.getProperty("spring.es.port");
	String clusterName = env.getProperty("spring.es.cluster_name");
	
	Builder builder = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", true);
	Settings esSettings = builder.build();
	TransportClient client = new PreBuiltTransportClient(esSettings);
	client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), Integer.parseInt(port)));
	logger.info("ES Client 初始化成功, ip : {}, port : {}, cluster_name : {}", ip, port, clusterName);
	return client;
}
 
開發者ID:SnailFastGo,項目名稱:springboot_op,代碼行數:14,代碼來源:ElasticsearchConfiguration.java


注:本文中的org.elasticsearch.common.transport.InetSocketTransportAddress類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。