}
@Override
protected XContentBuilder toXContent(ClusterStateRequest request, ClusterStateResponse response, XContentBuilder builder) throws IOException {
MetaData metaData = response.getState().metaData();
builder.startObject();
if (metaData.indices().isEmpty()) {
return builder.endObject();
}
Set<String> typesSet;
if (types != null) {
typesSet = ImmutableSet.copyOf(types);
} else {
typesSet = ImmutableSet.of();
}
if (request.filteredIndices() != null && request.filteredIndices().length == 1 && typesSet.size() == 1) {
boolean foundType = false;
IndexMetaData indexMetaData = metaData.iterator().next();
for (MappingMetaData mappingMd : indexMetaData.mappings().values()) {
if (!typesSet.isEmpty() && !typesSet.contains(mappingMd.type())) {
// filter this type out...
continue;
}