Search in sources :

Example 6 with GetMappingsRequest

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project pancm_project by xuwujing.

the class EsHighLevelRestTest1 method getMapping.

private static void getMapping() throws IOException {
    String index = "student";
    GetMappingsRequest request = new GetMappingsRequest();
    request.indices(index);
    GetMappingsResponse response = client.indices().getMapping(request, RequestOptions.DEFAULT);
    System.out.println("mapping " + response);
    System.out.println("mapping " + response.mappings());
    response.getMappings().forEach(k -> {
        System.out.println("" + k.key);
        System.out.println("" + k.value);
        System.out.println("" + k.value.get(k.key));
    });
}
Also used : GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 7 with GetMappingsRequest

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project canal by alibaba.

the class ESConnection method getMapping.

public MappingMetaData getMapping(String index, String type) {
    MappingMetaData mappingMetaData = null;
    if (mode == ESClientMode.TRANSPORT) {
        ImmutableOpenMap<String, MappingMetaData> mappings;
        try {
            mappings = transportClient.admin().cluster().prepareState().execute().actionGet().getState().getMetaData().getIndices().get(index).getMappings();
        } catch (NullPointerException e) {
            throw new IllegalArgumentException("Not found the mapping info of index: " + index);
        }
        mappingMetaData = mappings.get(type);
    } else {
        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings;
        try {
            GetMappingsRequest request = new GetMappingsRequest();
            request.indices(index);
            GetMappingsResponse response;
            // try {
            // response = restHighLevelClient
            // .indices()
            // .getMapping(request, RequestOptions.DEFAULT);
            // // 6.4以下版本直接使用该接口会报错
            // } catch (Exception e) {
            // logger.warn("Low ElasticSearch version for getMapping");
            response = RestHighLevelClientExt.getMapping(restHighLevelClient, request, RequestOptions.DEFAULT);
            // }
            mappings = response.mappings();
        } catch (NullPointerException e) {
            throw new IllegalArgumentException("Not found the mapping info of index: " + index);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            return null;
        }
        mappingMetaData = mappings.get(index).get(type);
    }
    return mappingMetaData;
}
Also used : IOException(java.io.IOException) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 8 with GetMappingsRequest

use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project calcite by apache.

the class Elasticsearch5Schema method getTableMap.

@Override
protected Map<String, Table> getTableMap() {
    final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
    try {
        final GetMappingsResponse response = client.admin().indices().getMappings(new GetMappingsRequest().indices(index)).get();
        ImmutableOpenMap<String, MappingMetaData> mapping = response.getMappings().get(index);
        for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
            builder.put(c.key, new Elasticsearch5Table(client, index, c.key));
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return builder.build();
}
Also used : Table(org.apache.calcite.schema.Table) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) ImmutableMap(com.google.common.collect.ImmutableMap) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Aggregations

GetMappingsRequest (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest)8 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)6 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Table (org.apache.calcite.schema.Table)2 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ClusterSearchShardsRequest (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)1 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)1 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)1 ClearIndicesCacheRequest (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)1 CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)1 TypesExistsRequest (org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest)1