Getting _settings or _mapping for non-existing index returns 200 OK, closes #1828.
This commit is contained in:
parent
cdfa87827a
commit
009731c9e7
|
@ -41,6 +41,7 @@ import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
import static org.elasticsearch.rest.action.support.RestActions.splitIndices;
|
import static org.elasticsearch.rest.action.support.RestActions.splitIndices;
|
||||||
import static org.elasticsearch.rest.action.support.RestActions.splitTypes;
|
import static org.elasticsearch.rest.action.support.RestActions.splitTypes;
|
||||||
|
@ -72,15 +73,18 @@ public class RestGetMappingAction extends BaseRestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(ClusterStateResponse response) {
|
public void onResponse(ClusterStateResponse response) {
|
||||||
try {
|
try {
|
||||||
|
boolean foundAny = false;
|
||||||
|
|
||||||
MetaData metaData = response.state().metaData();
|
MetaData metaData = response.state().metaData();
|
||||||
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
||||||
if (indices.length == 1 && types.size() == 1) {
|
if (indices.length == 1 && metaData.indices().isEmpty()) {
|
||||||
if (metaData.indices().isEmpty()) {
|
|
||||||
channel.sendResponse(new XContentThrowableRestResponse(request, new IndexMissingException(new Index(indices[0]))));
|
channel.sendResponse(new XContentThrowableRestResponse(request, new IndexMissingException(new Index(indices[0]))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (indices.length == 1 && types.size() == 1) {
|
||||||
boolean foundType = false;
|
boolean foundType = false;
|
||||||
IndexMetaData indexMetaData = metaData.iterator().next();
|
IndexMetaData indexMetaData = metaData.iterator().next();
|
||||||
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
|
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
|
||||||
|
@ -88,6 +92,7 @@ public class RestGetMappingAction extends BaseRestHandler {
|
||||||
// filter this type out...
|
// filter this type out...
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
foundAny = true;
|
||||||
foundType = true;
|
foundType = true;
|
||||||
builder.field(mappingMd.type());
|
builder.field(mappingMd.type());
|
||||||
builder.map(mappingMd.sourceAsMap());
|
builder.map(mappingMd.sourceAsMap());
|
||||||
|
@ -105,6 +110,7 @@ public class RestGetMappingAction extends BaseRestHandler {
|
||||||
// filter this type out...
|
// filter this type out...
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
foundAny = true;
|
||||||
builder.field(mappingMd.type());
|
builder.field(mappingMd.type());
|
||||||
builder.map(mappingMd.sourceAsMap());
|
builder.map(mappingMd.sourceAsMap());
|
||||||
}
|
}
|
||||||
|
@ -115,7 +121,7 @@ public class RestGetMappingAction extends BaseRestHandler {
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
channel.sendResponse(new XContentRestResponse(request, OK, builder));
|
channel.sendResponse(new XContentRestResponse(request, foundAny ? OK : NOT_FOUND, builder));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
onFailure(e);
|
onFailure(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsFilter;
|
import org.elasticsearch.common.settings.SettingsFilter;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.index.Index;
|
||||||
|
import org.elasticsearch.indices.IndexMissingException;
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||||
|
|
||||||
|
@ -37,6 +39,7 @@ import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
import static org.elasticsearch.rest.action.support.RestActions.splitIndices;
|
import static org.elasticsearch.rest.action.support.RestActions.splitIndices;
|
||||||
|
|
||||||
|
@ -67,12 +70,19 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
||||||
public void onResponse(ClusterStateResponse response) {
|
public void onResponse(ClusterStateResponse response) {
|
||||||
try {
|
try {
|
||||||
MetaData metaData = response.state().metaData();
|
MetaData metaData = response.state().metaData();
|
||||||
|
|
||||||
|
if (metaData.indices().isEmpty()) {
|
||||||
|
channel.sendResponse(new XContentThrowableRestResponse(request, new IndexMissingException(new Index(indices[0]))));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean foundAny = false;
|
||||||
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
||||||
for (IndexMetaData indexMetaData : metaData) {
|
for (IndexMetaData indexMetaData : metaData) {
|
||||||
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
|
builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
|
||||||
|
foundAny = true;
|
||||||
builder.startObject("settings");
|
builder.startObject("settings");
|
||||||
Settings settings = settingsFilter.filterSettings(indexMetaData.settings());
|
Settings settings = settingsFilter.filterSettings(indexMetaData.settings());
|
||||||
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
||||||
|
@ -85,7 +95,7 @@ public class RestGetSettingsAction extends BaseRestHandler {
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
channel.sendResponse(new XContentRestResponse(request, OK, builder));
|
channel.sendResponse(new XContentRestResponse(request, foundAny ? OK : NOT_FOUND, builder));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
onFailure(e);
|
onFailure(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue