use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project elasticsearch by elastic.
the class IndicesRequestIT method testGetMappings.
public void testGetMappings() {
interceptTransportActions(GetMappingsAction.NAME);
GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(randomIndicesOrAliases());
internalCluster().coordOnlyNodeClient().admin().indices().getMappings(getMappingsRequest).actionGet();
clearInterceptedActions();
assertSameIndices(getMappingsRequest, GetMappingsAction.NAME);
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project incubator-sdap-mudrod by apache.
the class ESDriver method getTypeListWithPrefix.
public List<String> getTypeListWithPrefix(Object object, Object object2) {
ArrayList<String> typeList = new ArrayList<>();
GetMappingsResponse res;
try {
res = getClient().admin().indices().getMappings(new GetMappingsRequest().indices(object.toString())).get();
ImmutableOpenMap<String, MappingMetaData> mapping = res.mappings().get(object.toString());
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
if (c.key.startsWith(object2.toString())) {
typeList.add(c.key);
}
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error whilst obtaining type list from Elasticsearch mappings.", e);
}
return typeList;
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project calcite by apache.
the class Elasticsearch2Schema method getTableMap.
@Override
protected Map<String, Table> getTableMap() {
final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();
try {
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 Elasticsearch2Table(client, index, c.key));
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest in project elasticsearch by elastic.
the class RestGetMappingAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
getMappingsRequest.indices(indices).types(types);
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(GetMappingsResponse response, XContentBuilder builder) throws Exception {
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
if (mappingsByIndex.isEmpty()) {
if (indices.length != 0 && types.length != 0) {
return new BytesRestResponse(OK, builder.startObject().endObject());
} else if (indices.length != 0) {
builder.close();
return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
} else if (types.length != 0) {
builder.close();
return new BytesRestResponse(channel, new TypeMissingException("_all", types[0]));
} else {
return new BytesRestResponse(OK, builder.startObject().endObject());
}
}
builder.startObject();
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappingsByIndex) {
if (indexEntry.value.isEmpty()) {
continue;
}
builder.startObject(indexEntry.key);
builder.startObject(Fields.MAPPINGS);
for (ObjectObjectCursor<String, MappingMetaData> typeEntry : indexEntry.value) {
builder.field(typeEntry.key);
builder.map(typeEntry.value.sourceAsMap());
}
builder.endObject();
builder.endObject();
}
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
}
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;
}
Aggregations