org.elasticsearch.client.RestHighLevelClient.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中org.elasticsearch.client.RestHighLevelClient.<init>方法的一些代码示例,展示了RestHighLevelClient.<init>的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestHighLevelClient.<init>方法的具体详情如下:
包路径:org.elasticsearch.client.RestHighLevelClient
类名称:RestHighLevelClient
方法名:<init>

RestHighLevelClient.<init>介绍

[英]Creates a RestHighLevelClient given the low level RestClientBuilder that allows to build the RestClient to be used to perform requests.
[中]

代码示例

代码示例来源:origin: spring-projects/spring-data-elasticsearch

protected void buildClient() throws Exception {
  Assert.hasText(hosts, "[Assertion Failed] At least one host must be set.");
  ArrayList<HttpHost> httpHosts = new ArrayList<HttpHost>();
  for (String host : hosts.split(COMMA)) {
    URL hostUrl = new URL(host);
    httpHosts.add(new HttpHost(hostUrl.getHost(), hostUrl.getPort(), hostUrl.getProtocol()));
  }
  client = new RestHighLevelClient(RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()])));
}

代码示例来源:origin: apache/flink

@Override
public RestHighLevelClient createClient(Map<String, String> clientConfig) throws IOException {
  RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()]));
  restClientFactory.configureRestClientBuilder(builder);
  RestHighLevelClient rhlClient = new RestHighLevelClient(builder);
  if (LOG.isInfoEnabled()) {
    LOG.info("Pinging Elasticsearch cluster via hosts {} ...", httpHosts);
  }
  if (!rhlClient.ping()) {
    throw new RuntimeException("There are no reachable Elasticsearch nodes!");
  }
  if (LOG.isInfoEnabled()) {
    LOG.info("Created Elasticsearch RestHighLevelClient connected to {}", httpHosts.toString());
  }
  return rhlClient;
}

代码示例来源:origin: Netflix/conductor

@Inject
public ElasticSearchRestDAOV5(RestClient lowLevelRestClient, ElasticSearchConfiguration config, ObjectMapper objectMapper) {
  this.objectMapper = objectMapper;
  this.elasticSearchAdminClient = lowLevelRestClient;
  this.elasticSearchClient = new RestHighLevelClient(lowLevelRestClient);
  this.indexName = config.getIndexName();
  this.logIndexPrefix = config.getTasklogIndexName();
  this.clusterHealthColor = config.getClusterHealthColor();
  // Set up a workerpool for performing async operations.
  int corePoolSize = 6;
  int maximumPoolSize = 12;
  long keepAliveTime = 1L;
  this.executorService = new ThreadPoolExecutor(corePoolSize,
      maximumPoolSize,
      keepAliveTime,
      TimeUnit.MINUTES,
      new LinkedBlockingQueue<>());
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

});
RestHighLevelClient client = new RestHighLevelClient(builder);
return () -> client;

代码示例来源:origin: apache/incubator-gobblin

this.lowLevelClient = buildRestClient(this.hostAddresses, threadCount);
client = new RestHighLevelClient(this.lowLevelClient);

代码示例来源:origin: apache/nifi

this.highLevelClient = new RestHighLevelClient(client);

代码示例来源:origin: Netflix/conductor

@BeforeClass
public static void startServer() throws Exception {
  System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9204");
  System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "http://localhost:9204");
  configuration = new SystemPropertiesElasticSearchConfiguration();
  String host = configuration.getEmbeddedHost();
  int port = configuration.getEmbeddedPort();
  String clusterName = configuration.getEmbeddedClusterName();
  embeddedElasticSearch = new EmbeddedElasticSearchV5(clusterName, host, port);
  embeddedElasticSearch.start();
  ElasticSearchRestClientProvider restClientProvider =
      new ElasticSearchRestClientProvider(configuration);
  restClient = restClientProvider.get();
  elasticSearchClient = new RestHighLevelClient(restClient);
  Map<String, String> params = new HashMap<>();
  params.put("wait_for_status", "yellow");
  params.put("timeout", "30s");
  restClient.performRequest("GET", "/_cluster/health", params);
  objectMapper = new ObjectMapper();
  indexDAO = new ElasticSearchRestDAOV5(restClient, configuration, objectMapper);
}

代码示例来源:origin: tomoya92/pybbs

@Override
public RestHighLevelClient instance() {
 if (this.client != null) return client;
 try {
  SystemConfig systemConfigHost = systemConfigService.selectByKey("elasticsearch_host");
  String host = systemConfigHost.getValue();
  SystemConfig systemConfigPort = systemConfigService.selectByKey("elasticsearch_port");
  String port = systemConfigPort.getValue();
  SystemConfig systemConfigName = systemConfigService.selectByKey("elasticsearch_index");
  name = systemConfigName.getValue();
  if (StringUtils.isEmpty(host) || StringUtils.isEmpty(port)) return null;
  client = new RestHighLevelClient(
    RestClient.builder(
      new HttpHost(host, Integer.parseInt(port), "http")));
  // 判断索引是否存在,不存在创建
  if (!this.existIndex()) this.createIndex("topic", topicMappingBuilder);
  return client;
 } catch (NumberFormatException e) {
  log.error(e.getMessage());
  return null;
 }
}

代码示例来源:origin: io.reactiverse/elasticsearch-client

RestHighLevelClientImpl(Vertx vertx, RestClientBuilder restClientBuilder) {
  this.vertx = vertx;
  this.restClientBuilder = restClientBuilder;
  this.delegate = new org.elasticsearch.client.RestHighLevelClient(restClientBuilder);
}

代码示例来源:origin: dadoonet/fscrawler

try {
  this.client = new RestHighLevelClient(lowLevelClient);
  checkVersion();
  logger.info("Elasticsearch Client for version {}.x connected to a node running version {}", compatibleVersion(), getVersion());

代码示例来源:origin: apache/metron

/**
 * Creates an Elasticsearch client from settings provided via the global config.
 *
 * @return new client
 */
public static ElasticsearchClient create(Map<String, Object> globalConfig) {
 ElasticsearchClientConfig esClientConfig = new ElasticsearchClientConfig(
   getEsSettings(globalConfig));
 HttpHost[] httpHosts = getHttpHosts(globalConfig, esClientConfig.getConnectionScheme());
 RestClientBuilder builder = RestClient.builder(httpHosts);
 builder.setRequestConfigCallback(reqConfigBuilder -> {
  // Modifies request config builder with connection and socket timeouts.
  // https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/_timeouts.html
  reqConfigBuilder.setConnectTimeout(esClientConfig.getConnectTimeoutMillis());
  reqConfigBuilder.setSocketTimeout(esClientConfig.getSocketTimeoutMillis());
  return reqConfigBuilder;
 });
 builder.setMaxRetryTimeoutMillis(esClientConfig.getMaxRetryTimeoutMillis());
 builder.setHttpClientConfigCallback(clientBuilder -> {
  clientBuilder.setDefaultIOReactorConfig(getIOReactorConfig(esClientConfig));
  clientBuilder.setDefaultCredentialsProvider(getCredentialsProvider(esClientConfig));
  clientBuilder.setSSLContext(getSSLContext(esClientConfig));
  return clientBuilder;
 });
 RestClient lowLevelClient = builder.build();
 RestHighLevelClient client = new RestHighLevelClient(lowLevelClient);
 return new ElasticsearchClient(lowLevelClient, client);
}

代码示例来源:origin: dadoonet/fscrawler

@Override
public void start() throws IOException {
  if (client != null) {
    // The client has already been initialized. Let's skip this again
    return;
  }
  try {
    // Create an elasticsearch client
    client = new RestHighLevelClient(buildRestClient(settings.getElasticsearch()));
    checkVersion();
    logger.info("Elasticsearch Client for version {}.x connected to a node running version {}", compatibleVersion(), getVersion());
  } catch (Exception e) {
    logger.warn("failed to create elasticsearch client, disabling crawler...");
    throw e;
  }
  if (settings.getElasticsearch().getPipeline() != null) {
    // Check that the pipeline exists
    if (!isExistingPipeline(settings.getElasticsearch().getPipeline())) {
      throw new RuntimeException("You defined pipeline:" + settings.getElasticsearch().getPipeline() +
          ", but it does not exist.");
    }
  }
  BiConsumer<BulkRequest, ActionListener<BulkResponse>> bulkConsumer =
      (request, bulkListener) -> client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener);
  bulkProcessor = BulkProcessor.builder(bulkConsumer, new DebugListener(logger))
      .setBulkActions(settings.getElasticsearch().getBulkSize())
      .setFlushInterval(TimeValue.timeValueMillis(settings.getElasticsearch().getFlushInterval().millis()))
      .setBulkSize(new ByteSizeValue(settings.getElasticsearch().getByteSize().getBytes()))
      .build();
}

代码示例来源:origin: dadoonet/fscrawler

@Override
public void start() throws IOException {
  if (client != null) {
    // The client has already been initialized. Let's skip this again
    return;
  }
  try {
    // Create an elasticsearch client
    client = new RestHighLevelClient(buildRestClient(settings.getElasticsearch()));
    checkVersion();
    logger.info("Elasticsearch Client for version {}.x connected to a node running version {}", compatibleVersion(), getVersion());
  } catch (Exception e) {
    logger.warn("failed to create elasticsearch client, disabling crawler...");
    throw e;
  }
  if (settings.getElasticsearch().getPipeline() != null) {
    // Check that the pipeline exists
    if (!isExistingPipeline(settings.getElasticsearch().getPipeline())) {
      throw new RuntimeException("You defined pipeline:" + settings.getElasticsearch().getPipeline() +
          ", but it does not exist.");
    }
  }
  BiConsumer<BulkRequest, ActionListener<BulkResponse>> bulkConsumer =
      (request, bulkListener) -> client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener);
  bulkProcessor = BulkProcessor.builder(bulkConsumer, new DebugListener(logger))
      .setBulkActions(settings.getElasticsearch().getBulkSize())
      .setFlushInterval(TimeValue.timeValueMillis(settings.getElasticsearch().getFlushInterval().millis()))
      .setBulkSize(new ByteSizeValue(settings.getElasticsearch().getByteSize().getBytes()))
      .build();
}

代码示例来源:origin: DomoXian/elastic-demo

public RestHighLevelClient getRestHighLevelClient() {
  if (restHighLevelClient == null) {
    restHighLevelClient = new RestHighLevelClient(RestClient.builder(httpHost));
  }
  return restHighLevelClient;
}

代码示例来源:origin: DTStack/flinkx

public static RestHighLevelClient getClient(String address) {
  List<HttpHost> httpHostList = new ArrayList<>();
  String[] addr = address.split(",");
  for(String add : addr) {
    String[] pair = add.split(":");
    TelnetUtil.telnet(pair[0], Integer.valueOf(pair[1]));
    httpHostList.add(new HttpHost(pair[0], Integer.valueOf(pair[1]), "http"));
  }
  RestHighLevelClient client = new RestHighLevelClient(
      RestClient.builder(httpHostList.toArray(new HttpHost[httpHostList.size()])));
  return client;
}

代码示例来源:origin: com.jslsolucoes/elasticsearch-ee

@Produces
public RestHighLevelClient create() {
return new RestHighLevelClient(RestClient.builder(elasticSearch.getHosts()));
}

代码示例来源:origin: org.nuxeo.elasticsearch/nuxeo-elasticsearch-core

protected ESClient createLocalRestClient(ElasticSearchEmbeddedServerConfig serverConfig) {
  if (!serverConfig.httpEnabled()) {
    throw new IllegalArgumentException(
        "Embedded configuration has no HTTP port enable, use TransportClient instead of Rest");
  }
  RestClientBuilder lowLevelRestClientBuilder = RestClient.builder(
      new HttpHost("localhost", Integer.parseInt(serverConfig.getHttpPort())));
  RestHighLevelClient client = new RestHighLevelClient(lowLevelRestClientBuilder); // NOSONAR (factory)
  // checkConnection(client);
  return new ESRestClient(client.getLowLevelClient(), client);
}

代码示例来源:origin: tmobile/pacbot

/**
 * Instantiates a new elastic search data publisher.
 */
public ElasticSearchDataPublisher() {
  restClient = RestClient.builder(new HttpHost(ESUtils.getESHost(), ESUtils.getESPort())).build();
  client = new RestHighLevelClient(restClient);
}

代码示例来源:origin: hakdogan/ElasticSearch

@Profile({"production", "docker"})
@Bean(destroyMethod = "close")
public RestHighLevelClient getRestClient() {
  return new RestHighLevelClient(RestClient.builder(new HttpHost(props.getClients().getHostname(),
      props.getClients().getHttpPort(), props.getClients().getScheme())));
}

代码示例来源:origin: zeebe-io/zeebe

private RestHighLevelClient createClient() {
 final HttpHost httpHost = urlToHttpHost(configuration.url);
 // use single thread for rest client
 final RestClientBuilder builder =
   RestClient.builder(httpHost)
     .setHttpClientConfigCallback(
       httpClientBuilder ->
         httpClientBuilder.setDefaultIOReactorConfig(
           IOReactorConfig.custom().setIoThreadCount(1).build()));
 return new RestHighLevelClient(builder);
}

相关文章