use of org.elasticsearch.index.IndexNotFoundException 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.index.IndexNotFoundException in project elasticsearch by elastic.
the class TransportPutMappingAction method masterOperation.
@Override
protected void masterOperation(final PutMappingRequest request, final ClusterState state, final ActionListener<PutMappingResponse> listener) {
try {
final Index[] concreteIndices = request.getConcreteIndex() == null ? indexNameExpressionResolver.concreteIndices(state, request) : new Index[] { request.getConcreteIndex() };
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest().ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices).type(request.type()).updateAllTypes(request.updateAllTypes()).source(request.source());
metaDataMappingService.putMapping(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {
@Override
public void onResponse(ClusterStateUpdateResponse response) {
listener.onResponse(new PutMappingResponse(response.isAcknowledged()));
}
@Override
public void onFailure(Exception t) {
logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", concreteIndices, request.type()), t);
listener.onFailure(t);
}
});
} catch (IndexNotFoundException ex) {
logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put mappings on indices [{}], type [{}]", request.indices(), request.type()), ex);
throw ex;
}
}
use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.
the class AutoCreateIndexTests method testAutoCreationDisabled.
public void testAutoCreationDisabled() {
Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), false).build();
AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(randomAsciiOfLengthBetween(1, 10), buildClusterState()));
assertEquals("no such index and [action.auto_create_index] is [false]", e.getMessage());
}
use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.
the class AutoCreateIndexTests method expectNotMatch.
private void expectNotMatch(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index) {
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(index, clusterState));
assertEquals("no such index and [action.auto_create_index] ([" + autoCreateIndex.getAutoCreate() + "]) doesn't match", e.getMessage());
}
use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.
the class AutoCreateIndexTests method expectForbidden.
private void expectForbidden(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index, String forbiddingPattern) {
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(index, clusterState));
assertEquals("no such index and [action.auto_create_index] contains [" + forbiddingPattern + "] which forbids automatic creation of the index", e.getMessage());
}
Aggregations