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

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

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

RestHighLevelClient.getLowLevelClient介绍

[英]Returns the low-level client that the current high-level client instance is using to perform requests
[中]返回当前高级客户端实例用于执行请求的低级客户端

代码示例

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

/**
 * Apply the configuration to create a {@link RestClient}.
 *
 * @return new instance of {@link RestClient}.
 */
default RestClient lowLevelRest() {
  return rest().getLowLevelClient();
}

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

@Override
public boolean typeExists(String index, String type) {
  RestClient restClient = client.getLowLevelClient();
  try {
    Response response = restClient.performRequest("HEAD", index + "/_mapping/" + type);
    return (response.getStatusLine().getStatusCode() == 200);
  } catch (Exception e) {
    throw new ElasticsearchException("Error while checking type exists for index: " + index + " type : " + type + " ",
        e);
  }
}

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

@Override // TODO change interface to return Settings.
public Map getSetting(String indexName) {
  Assert.notNull(indexName, "No index defined for getSettings");
  ObjectMapper objMapper = new ObjectMapper();
  Map settings = null;
  RestClient restClient = client.getLowLevelClient();
  try {
    Response response = restClient.performRequest("GET", "/" + indexName + "/_settings");
    settings = convertSettingResponse(EntityUtils.toString(response.getEntity()), indexName);
  } catch (Exception e) {
    throw new ElasticsearchException("Error while getting settings for indexName : " + indexName, e);
  }
  return settings;
}

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

@Override
public Map getMapping(String indexName, String type) {
  Assert.notNull(indexName, "No index defined for getMapping()");
  Assert.notNull(type, "No type defined for getMapping()");
  Map mappings = null;
  RestClient restClient = client.getLowLevelClient();
  try {
    Response response = restClient.performRequest("GET", "/" + indexName + "/_mapping/" + type);
    mappings = convertMappingResponse(EntityUtils.toString(response.getEntity()), type);
  } catch (Exception e) {
    throw new ElasticsearchException(
        "Error while getting mapping for indexName : " + indexName + " type : " + type + " ", e);
  }
  return mappings;
}

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

@Override
public List<AliasMetaData> queryForAlias(String indexName) {
  List<AliasMetaData> aliases = null;
  RestClient restClient = client.getLowLevelClient();
  Response response;
  String aliasResponse;
  try {
    response = restClient.performRequest("GET", "/" + indexName + "/_alias/*");
    aliasResponse = EntityUtils.toString(response.getEntity());
  } catch (Exception e) {
    throw new ElasticsearchException("Error while getting mapping for indexName : " + indexName, e);
  }
  return convertAliasResponse(aliasResponse);
}

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

/**
 * Reindex data from one index/type to another index
 * @param sourceIndex source index name
 * @param sourceType source type name
 * @param targetIndex target index name
 * @return The number of documents that have been reindexed
 * @throws IOException In case of error
 */
public int reindex(String sourceIndex, String sourceType, String targetIndex) throws IOException {
  logger.debug("reindex [{}]/[{}] -> [{}]/[doc]", sourceIndex, sourceType, targetIndex);
  String reindexQuery = "{  \"source\": {\n" +
      "    \"index\": \"" + sourceIndex + "\",\n" +
      "    \"type\": \"" + sourceType + "\"\n" +
      "  },\n" +
      "  \"dest\": {\n" +
      "    \"index\": \"" + targetIndex + "\",\n" +
      "    \"type\": \"doc\"\n" +
      "  }\n" +
      "}\n";
  logger.trace("{}", reindexQuery);
  Request request = new Request("POST", "/_reindex");
  request.setJsonEntity(reindexQuery);
  Response restResponse = client.getLowLevelClient().performRequest(request);
  Map<String, Object> response = asMap(restResponse);
  logger.debug("reindex response: {}", response);
  return (int) response.get("total");
}

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

/**
 * Reindex data from one index/type to another index
 * @param sourceIndex source index name
 * @param sourceType source type name
 * @param targetIndex target index name
 * @return The number of documents that have been reindexed
 * @throws IOException In case of error
 */
public int reindex(String sourceIndex, String sourceType, String targetIndex) throws IOException {
  logger.debug("reindex [{}]/[{}] -> [{}]/[doc]", sourceIndex, sourceType, targetIndex);
  String reindexQuery = "{  \"source\": {\n" +
      "    \"index\": \"" + sourceIndex + "\",\n" +
      "    \"type\": \"" + sourceType + "\"\n" +
      "  },\n" +
      "  \"dest\": {\n" +
      "    \"index\": \"" + targetIndex + "\",\n" +
      "    \"type\": \"doc\"\n" +
      "  }\n" +
      "}\n";
  logger.trace("{}", reindexQuery);
  Request request = new Request("POST", "/_reindex");
  request.setJsonEntity(reindexQuery);
  Response restResponse = client.getLowLevelClient().performRequest(request);
  Map<String, Object> response = asMap(restResponse);
  logger.debug("reindex response: {}", response);
  return (int) response.get("total");
}

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

/**
 * Fully removes a type from an index (removes data)
 * @param index index name
 * @param type type
 * @throws IOException In case of error
 */
public void deleteByQuery(String index, String type) throws IOException {
  logger.debug("deleteByQuery [{}]/[{}]", index, type);
  String deleteByQuery = "{\n" +
      "  \"query\": {\n" +
      "    \"match_all\": {}\n" +
      "  }\n" +
      "}";
  Request request = new Request("POST", "/" + index + "/" + type + "/_delete_by_query");
  request.setJsonEntity(deleteByQuery);
  Response restResponse = client.getLowLevelClient().performRequest(request);
  Map<String, Object> response = asMap(restResponse);
  logger.debug("reindex response: {}", response);
}

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

/**
 * Fully removes a type from an index (removes data)
 * @param index index name
 * @param type type
 * @throws IOException In case of error
 */
public void deleteByQuery(String index, String type) throws IOException {
  logger.debug("deleteByQuery [{}]/[{}]", index, type);
  String deleteByQuery = "{\n" +
      "  \"query\": {\n" +
      "    \"match_all\": {}\n" +
      "  }\n" +
      "}";
  Request request = new Request("POST", "/" + index + "/" + type + "/_delete_by_query");
  request.setJsonEntity(deleteByQuery);
  Response restResponse = client.getLowLevelClient().performRequest(request);
  Map<String, Object> response = asMap(restResponse);
  logger.debug("reindex response: {}", response);
}

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

@Override
public void performLowLevelRequest(String method, String endpoint, String jsonEntity) throws IOException {
  Request request = new Request(method, endpoint);
  if (!isNullOrEmpty(jsonEntity)) {
    request.setJsonEntity(jsonEntity);
  }
  client.getLowLevelClient().performRequest(request);
}

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

@Override
public void performLowLevelRequest(String method, String endpoint, String jsonEntity) throws IOException {
  Request request = new Request(method, endpoint);
  if (!isNullOrEmpty(jsonEntity)) {
    request.setJsonEntity(jsonEntity);
  }
  client.getLowLevelClient().performRequest(request);
}

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

/**
 * Init templates if needed.
 * <p>
 * Note that you can force to recreate template using
 * {@link #setForceTemplate(boolean)}
 */
private void initTemplates() throws Exception {
  if (templates != null && templates.length > 0) {
    for (String template : templates) {
      Assert.hasText(template, "Can not read template in ["
          + template
          + "]. Check that templates is not empty.");
      createTemplate(client.getLowLevelClient(), classpathRoot, template, forceTemplate);
    }
  }
}

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

/**
 * Init aliases if needed.
 */
private void initAliases() throws Exception {
  if (aliases != null && aliases.length > 0) {
    for (String aliase : aliases) {
      String[] aliasessplitted = aliase.split(":");
      String alias = aliasessplitted[0];
      String index = aliasessplitted[1];
      if (index == null) throw new Exception("Can not read index in [" + aliase +
          "]. Check that aliases contains only aliasname:indexname elements.");
      if (alias == null) throw new Exception("Can not read mapping in [" + aliase +
          "]. Check that aliases contains only aliasname:indexname elements.");
      createAlias(client.getLowLevelClient(), alias, index);
    }
  }
}

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

/**
 * Init mapping if needed.
 * <p>Note that you can force to reinit mapping using {@link #setForceMapping(boolean)}
 */
private void initMappings() throws Exception {
  checkClient();
  // We extract indexes and mappings to manage from mappings definition
  if (mappings != null && mappings.length > 0) {
    Map<String, Collection<String>> indices = getIndexMappings(mappings);
    // Let's initialize indexes and mappings if needed
    for (String index : indices.keySet()) {
      createIndex(client.getLowLevelClient(), classpathRoot, index, forceMapping);
      if (mergeSettings) {
        updateSettings(client.getLowLevelClient(), classpathRoot, index);
      }
      Collection<String> mappings = indices.get(index);
      for (String type : mappings) {
        createMapping(client.getLowLevelClient(), classpathRoot, index, type, mergeMapping);
      }
    }
  }
}

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

public void flush() throws IOException {
    String endPoint = String.join("/", props.getIndex().getName(), "_flush");
    client.getLowLevelClient().performRequest("POST", endPoint);
  }
}

代码示例来源:origin: SeaseLtd/rated-ranking-evaluator

Response response = client.getLowLevelClient().performRequest(GET_METHOD, CLUSTER_HEALTH_ENDPOINT);
String body = EntityUtils.toString(response.getEntity());
Map jsonMap = new ObjectMapper().readValue(body, Map.class);

代码示例来源: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: org.nuxeo.elasticsearch/nuxeo-elasticsearch-core

protected ESClient createRestClient(ElasticSearchClientConfig config) {
  String addressList = config.getOption("addressList", "");
  if (addressList.isEmpty()) {
    throw new IllegalArgumentException("No addressList option provided cannot connect RestClient");
  }
  String[] hosts = addressList.split(",");
  HttpHost[] httpHosts = new HttpHost[hosts.length];
  int i = 0;
  for (String host : hosts) {
    httpHosts[i++] = HttpHost.create(host);
  }
  RestClientBuilder builder = RestClient.builder(httpHosts)
                     .setRequestConfigCallback(
                         requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(
                             getConnectTimeoutMs(config))
                                               .setSocketTimeout(
                                                   getSocketTimeoutMs(
                                                       config)))
                     .setMaxRetryTimeoutMillis(getConnectTimeoutMs(config));
  addClientCallback(config, builder);
  RestHighLevelClient client = new RestHighLevelClient(builder); // NOSONAR (factory)
  // checkConnection(client);
  return new ESRestClient(client.getLowLevelClient(), client);
}

代码示例来源:origin: eea/eea.elasticsearch.river.rdf

RestClient lowclient = indexer.client.getLowLevelClient();

相关文章