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

x33g5p2x  于2022-01-20 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(97)

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

IndicesAdminClient.getMappings介绍

[英]Get the complete mappings of one or more types
[中]获取一个或多个类型的完整映射

代码示例

代码示例来源:origin: prestodb/presto

private ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> getMappings(TransportClient client, GetMappingsRequest request)
{
  try {
    return retry()
        .maxAttempts(maxAttempts)
        .exponentialBackoff(maxRetryTime)
        .run("getMappings", () -> client.admin()
            .indices()
            .getMappings(request)
            .actionGet(requestTimeout.toMillis())
            .getMappings());
  }
  catch (Exception e) {
    throw new RuntimeException(e);
  }
}

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

private boolean doesMappingExist(final String index, final String mappingName) {
  GetMappingsRequest request = new GetMappingsRequest()
      .indices(index);
  try {
    GetMappingsResponse response = elasticSearchClient.admin()
        .indices()
        .getMappings(request)
        .get();
    return response.getMappings()
        .get(index)
        .containsKey(mappingName);
  } catch (InterruptedException | ExecutionException e) {
    throw new RuntimeException(e);
  }
}

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

getMappingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout()));
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
  @Override
  public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {

代码示例来源:origin: dqeasycloud/easy-cloud

@Override
public Map<String, Object> getAllMapping(String indexName) throws Exception {
  Assert.notNull(indexName, "No index defined for putMapping()");
  Map<String, Object> map = new HashMap<>();
  try {
    ImmutableOpenMap<String, MappingMetaData> immutableOpenMap = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName))
        .actionGet().getMappings().get(indexName);
    Iterator<ObjectObjectCursor<String, MappingMetaData>> iterator = immutableOpenMap.iterator();
    while (iterator.hasNext()) {
      ObjectObjectCursor<String, MappingMetaData> objectObjectCursor = iterator.next();
      map.put(objectObjectCursor.key, objectObjectCursor.value.getSourceAsMap());
    }
  } catch (Exception e) {
    throw new Exception("Error while getting mapping for indexName : " + indexName + e.getMessage());
  }
  return map;
}

代码示例来源:origin: dqeasycloud/easy-cloud

@Override
public Map<String, Object> getMapping(String indexName, String type) throws Exception {
  Assert.notNull(indexName, "No index defined for putMapping()");
  Assert.notNull(type, "No type defined for putMapping()");
  Map mappings = null;
  try {
    mappings = getIndicesAdminClient().getMappings(new GetMappingsRequest().indices(indexName).types(type))
        .actionGet().getMappings().get(indexName).get(type).getSourceAsMap();
  } catch (Exception e) {
    throw new Exception("Error while getting mapping for indexName : " + indexName + " type : " + type + " " + e.getMessage());
  }
  return mappings;
}

代码示例来源:origin: flaxsearch/BioSolr

@Override
public List<String> getDynamicFieldNames() throws SearchEngineException {
  List<String> fieldNames = new LinkedList<>();
  try {
    GetMappingsRequest req =
        new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE, configuration.getIndexName())
            .setTypes(configuration.getDocType())
            .request();
    GetMappingsResponse response = client.admin().indices().getMappings(req).actionGet();
    MappingMetaData metaData = response.getMappings()
        .get(configuration.getIndexName())
        .get(configuration.getDocType());
    Map<String, Object> sourceMap = metaData.getSourceAsMap();
    Object annotationField = ((Map)sourceMap.get("properties")).get(configuration.getAnnotationField());
    Map<String, Object> annotationProperties = (Map<String, Object>)((Map)annotationField).get("properties");
    if (annotationProperties != null) {
      for (String field : annotationProperties.keySet()) {
        if (field.matches(DYNAMIC_LABEL_FIELD_REGEX)) {
          fieldNames.add(field);
        }
      }
    }
  } catch (IOException e) {
    LOGGER.error("Caught IOException retrieving field source: {}", e.getMessage());
    throw new SearchEngineException(e);
  }
  return fieldNames;
}

代码示例来源:origin: org.eclipse.kapua/kapua-datastore-client-transport

@Override
public void putMapping(TypeDescriptor typeDescriptor, JsonNode mapping) throws ClientException {
  checkClient();
  // Check message type mapping
  GetMappingsRequest mappingsRequest = new GetMappingsRequest().indices(typeDescriptor.getIndex());
  GetMappingsResponse mappingsResponse = esClientProvider.getClient().admin().indices().getMappings(mappingsRequest).actionGet(getQueryTimeout());
  ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappingsResponse.getMappings();
  ImmutableOpenMap<String, MappingMetaData> map = mappings.get(typeDescriptor.getIndex());
  MappingMetaData metadata = map.get(typeDescriptor.getType());
  if (metadata == null) {
    logger.debug("Put mapping: '{}'", mapping);
    esClientProvider.getClient().admin().indices().preparePutMapping(typeDescriptor.getIndex()).setType(typeDescriptor.getType()).setSource(mapping.toString(), XContentType.JSON)
        .execute().actionGet(getQueryTimeout());
    logger.trace("Put mapping - mapping {} created! ", typeDescriptor.getType());
  } else {
    logger.trace("Put mapping - mapping {} already exists! ", typeDescriptor.getType());
  }
}

代码示例来源:origin: eclipse/kapua

@Override
public void putMapping(TypeDescriptor typeDescriptor, JsonNode mapping) throws ClientException {
  checkClient();
  // Check message type mapping
  GetMappingsRequest mappingsRequest = new GetMappingsRequest().indices(typeDescriptor.getIndex());
  GetMappingsResponse mappingsResponse = esClientProvider.getClient().admin().indices().getMappings(mappingsRequest).actionGet(getQueryTimeout());
  ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappingsResponse.getMappings();
  ImmutableOpenMap<String, MappingMetaData> map = mappings.get(typeDescriptor.getIndex());
  MappingMetaData metadata = map.get(typeDescriptor.getType());
  if (metadata == null) {
    logger.debug("Put mapping: '{}'", mapping);
    esClientProvider.getClient().admin().indices().preparePutMapping(typeDescriptor.getIndex()).setType(typeDescriptor.getType()).setSource(mapping.toString(), XContentType.JSON)
        .execute().actionGet(getQueryTimeout());
    logger.trace("Put mapping - mapping {} created! ", typeDescriptor.getType());
  } else {
    logger.trace("Put mapping - mapping {} already exists! ", typeDescriptor.getType());
  }
}

代码示例来源:origin: eclipse/kapua

@Override
public boolean isMappingExists(TypeDescriptor typeDescriptor) throws ClientException {
  checkClient();
  GetMappingsRequest mappingsRequest = new GetMappingsRequest().indices(typeDescriptor.getIndex());
  GetMappingsResponse mappingsResponse = esClientProvider.getClient().admin().indices().getMappings(mappingsRequest).actionGet(getQueryTimeout());
  ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappingsResponse.getMappings();
  ImmutableOpenMap<String, MappingMetaData> map = mappings.get(typeDescriptor.getIndex());
  MappingMetaData metadata = map.get(typeDescriptor.getType());
  return metadata != null;
}

代码示例来源:origin: org.eclipse.kapua/kapua-datastore-client-transport

@Override
public boolean isMappingExists(TypeDescriptor typeDescriptor) throws ClientException {
  checkClient();
  GetMappingsRequest mappingsRequest = new GetMappingsRequest().indices(typeDescriptor.getIndex());
  GetMappingsResponse mappingsResponse = esClientProvider.getClient().admin().indices().getMappings(mappingsRequest).actionGet(getQueryTimeout());
  ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappingsResponse.getMappings();
  ImmutableOpenMap<String, MappingMetaData> map = mappings.get(typeDescriptor.getIndex());
  MappingMetaData metadata = map.get(typeDescriptor.getType());
  return metadata != null;
}

代码示例来源:origin: harbby/presto-connectors

getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
  @Override
  public RestResponse buildResponse(GetMappingsResponse response, XContentBuilder builder) throws Exception {

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
  @Override
  public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

getMappingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout()));
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
  @Override
  public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {

代码示例来源:origin: apache/servicemix-bundles

getMappingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout()));
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestBuilderListener<GetMappingsResponse>(channel) {
  @Override
  public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {

相关文章

微信公众号

最新文章

更多

IndicesAdminClient类方法