Search in sources :

Example 56 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project wonderdog by infochimps-labs.

the class ElasticSearchStreamingInputFormat method startTransportClient.

// 
// == Connecting to Elasticsearch and Querying ==
// 
private void startTransportClient(JobConf conf) {
    this.client = new TransportClient();
    Map<String, String> settings = parsedSettings(conf);
    String host = hostname(settings);
    if (host.toString().length() == 0) {
        System.exit(1);
    }
    LOG.info("Attempting to connect to Elasticsearch node at " + host + ":9300");
    this.client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(host, 9300));
    LOG.info("Connected to Elasticsearch cluster");
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 57 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project apex-malhar by apache.

the class ElasticSearchConnectable method connect.

/*
   * (non-Javadoc)
   *
   * @see org.apache.apex.malhar.lib.db.Connectable#connect()
   */
@Override
public void connect() throws IOException {
    client = new TransportClient();
    client.addTransportAddress(new InetSocketTransportAddress(hostName, port));
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Example 58 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project uavstack by uavorg.

the class DoTestTransportHookProxy method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    ConsoleLogger cl = new ConsoleLogger("test");
    cl.setDebugable(true);
    UAVServer.instance().setLog(cl);
    UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
    MOFAgent.mofContext.put("org.uavstack.mof.ext.clsloader", Thread.currentThread().getContextClassLoader());
    TransportHookProxy p = new TransportHookProxy("test", Collections.emptyMap());
    p.doProxyInstall(null, "testApp");
    String[] esAddrs = { "127.0.0.1:9300" };
    String clusterName = "";
    String index = "esindex";
    String type = "String";
    String alias = "alias";
    Boolean result;
    Settings settings = Settings.EMPTY;
    if (!StringHelper.isEmpty(clusterName)) {
        settings = Settings.builder().put("cluster.name", clusterName).build();
    }
    TransportClient client = new PreBuiltTransportClient(settings);
    for (String esAddr : esAddrs) {
        String[] ipport = esAddr.split(":");
        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(ipport[0], DataConvertHelper.toInt(ipport[1], 9300))));
    }
    result = client.admin().indices().exists(new IndicesExistsRequest(index)).actionGet().isExists();
    if (result) {
        result = client.admin().indices().delete(new DeleteIndexRequest(index)).actionGet().isAcknowledged();
    }
    client.admin().indices().create(new CreateIndexRequest(index)).actionGet().isAcknowledged();
    client.admin().indices().typesExists(new TypesExistsRequest(new String[] { index }, type)).actionGet().isExists();
    client.admin().indices().prepareAliases().addAlias(index, alias).get().isAcknowledged();
    client.admin().indices().prepareAliases().removeAlias(index, alias).get().isAcknowledged();
    client.prepareSearch(index).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get(TimeValue.timeValueMillis(15000));
    Map<String, Object> m = new HashMap<String, Object>();
    m.put("user", "kimchy");
    m.put("postDate", new Date());
    m.put("message", "trying out Elasticsearch");
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    bulkRequest.add(client.prepareIndex("twitter", "tweet", "1").setSource(m));
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        System.out.println("Failed");
    }
    client.close();
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Date(java.util.Date) TransportHookProxy(com.creditease.uav.hook.esclient.transport.TransportHookProxy) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) Settings(org.elasticsearch.common.settings.Settings) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 59 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress in project springboot_op by SnailFastGo.

the class ElasticsearchConfiguration method initESClient.

@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;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) Builder(org.elasticsearch.common.settings.Settings.Builder) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) Bean(org.springframework.context.annotation.Bean)

Example 60 with InetSocketTransportAddress

use of org.elasticsearch.common.transport.InetSocketTransportAddress 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)

Aggregations

InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)69 TransportClient (org.elasticsearch.client.transport.TransportClient)37 Settings (org.elasticsearch.common.settings.Settings)35 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)25 UnknownHostException (java.net.UnknownHostException)17 InetSocketAddress (java.net.InetSocketAddress)11 TransportAddress (org.elasticsearch.common.transport.TransportAddress)10 HashMap (java.util.HashMap)8 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)7 Builder (org.elasticsearch.common.settings.Settings.Builder)7 ArrayList (java.util.ArrayList)6 Client (org.elasticsearch.client.Client)6 Bean (org.springframework.context.annotation.Bean)5 InetAddress (java.net.InetAddress)4 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4 Node (org.elasticsearch.node.Node)4 File (java.io.File)3 IOException (java.io.IOException)3 Properties (java.util.Properties)3