mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
parent
96af4ee44f
commit
6d8a85c6af
@ -31,7 +31,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.indices.IndexMissingException;
|
import org.elasticsearch.indices.IndexMissingException;
|
||||||
import org.elasticsearch.indices.TypeMissingException;
|
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||||
|
|
||||||
@ -82,45 +81,25 @@ public class RestGetMappingAction extends BaseRestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImmutableSet<String> uniqueTypes = ImmutableSet.copyOf(types);
|
ImmutableSet<String> uniqueTypes = ImmutableSet.copyOf(types);
|
||||||
|
for (Map.Entry<String, ImmutableMap<String, MappingMetaData>> indexEntry : mappingsByIndex.entrySet()) {
|
||||||
|
builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
|
||||||
|
|
||||||
if (indices.length == 1 && uniqueTypes.size() == 1) {
|
for (Map.Entry<String, MappingMetaData> typeEntry : indexEntry.getValue().entrySet()) {
|
||||||
boolean foundType = false;
|
if (!uniqueTypes.isEmpty() && !uniqueTypes.contains(typeEntry.getKey())) {
|
||||||
ImmutableMap<String, MappingMetaData> indexMetaData = mappingsByIndex.entrySet().iterator().next().getValue();
|
|
||||||
for (MappingMetaData mappingMd : indexMetaData.values()) {
|
|
||||||
if (!uniqueTypes.isEmpty() && !uniqueTypes.contains(mappingMd.type())) {
|
|
||||||
// filter this type out...
|
// filter this type out...
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foundAny = true;
|
foundAny = true;
|
||||||
foundType = true;
|
builder.field(typeEntry.getKey());
|
||||||
builder.field(mappingMd.type());
|
builder.map(typeEntry.getValue().sourceAsMap());
|
||||||
builder.map(mappingMd.sourceAsMap());
|
|
||||||
}
|
}
|
||||||
if (!foundType) {
|
|
||||||
channel.sendResponse(new XContentThrowableRestResponse(request, new TypeMissingException(new Index(indices[0]), uniqueTypes.iterator().next())));
|
if (indexEntry.getValue().isEmpty() && uniqueTypes.isEmpty()) {
|
||||||
return;
|
// if no types are specified and no mappings are set for the index, consider this an empty mapping
|
||||||
|
foundAny = true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for (Map.Entry<String, ImmutableMap<String, MappingMetaData>> indexEntry : mappingsByIndex.entrySet()) {
|
|
||||||
builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
|
|
||||||
|
|
||||||
for (Map.Entry<String, MappingMetaData> typeEntry : indexEntry.getValue().entrySet()) {
|
builder.endObject();
|
||||||
if (!uniqueTypes.isEmpty() && !uniqueTypes.contains(typeEntry.getKey())) {
|
|
||||||
// filter this type out...
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
foundAny = true;
|
|
||||||
builder.field(typeEntry.getKey());
|
|
||||||
builder.map(typeEntry.getValue().sourceAsMap());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexEntry.getValue().isEmpty() && uniqueTypes.isEmpty()) {
|
|
||||||
// if no types are specified and no mappings are set for the index, consider this an empty mapping
|
|
||||||
foundAny = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.endObject();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user