mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-16 09:54:55 +00:00
parent
a10c80e20f
commit
acc0950957
@ -240,14 +240,30 @@ public class IndexTemplateMetaData {
|
|||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
builder.startArray("mappings");
|
if (params.paramAsBoolean("reduce_mappings", false)) {
|
||||||
for (Map.Entry<String, CompressedString> entry : indexTemplateMetaData.mappings().entrySet()) {
|
builder.startObject("mappings");
|
||||||
byte[] data = entry.getValue().uncompressed();
|
for (Map.Entry<String, CompressedString> entry : indexTemplateMetaData.mappings().entrySet()) {
|
||||||
XContentParser parser = XContentFactory.xContent(data).createParser(data);
|
byte[] mappingSource = entry.getValue().uncompressed();
|
||||||
Map<String, Object> mapping = parser.mapOrderedAndClose();
|
XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
|
||||||
builder.map(mapping);
|
Map<String, Object> mapping = parser.map();
|
||||||
|
if (mapping.size() == 1 && mapping.containsKey(entry.getKey())) {
|
||||||
|
// the type name is the root value, reduce it
|
||||||
|
mapping = (Map<String, Object>) mapping.get(entry.getKey());
|
||||||
|
}
|
||||||
|
builder.field(entry.getKey());
|
||||||
|
builder.map(mapping);
|
||||||
|
}
|
||||||
|
builder.endObject();
|
||||||
|
} else {
|
||||||
|
builder.startArray("mappings");
|
||||||
|
for (Map.Entry<String, CompressedString> entry : indexTemplateMetaData.mappings().entrySet()) {
|
||||||
|
byte[] data = entry.getValue().uncompressed();
|
||||||
|
XContentParser parser = XContentFactory.xContent(data).createParser(data);
|
||||||
|
Map<String, Object> mapping = parser.mapOrderedAndClose();
|
||||||
|
builder.map(mapping);
|
||||||
|
}
|
||||||
|
builder.endArray();
|
||||||
}
|
}
|
||||||
builder.endArray();
|
|
||||||
|
|
||||||
for (Map.Entry<String, IndexMetaData.Custom> entry : indexTemplateMetaData.customs().entrySet()) {
|
for (Map.Entry<String, IndexMetaData.Custom> entry : indexTemplateMetaData.customs().entrySet()) {
|
||||||
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
|
builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE);
|
||||||
|
@ -26,8 +26,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface allowing to transfer an object to "XContent" using an {@link XContentBuilder}.
|
* An interface allowing to transfer an object to "XContent" using an {@link XContentBuilder}.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ToXContent {
|
public interface ToXContent {
|
||||||
|
|
||||||
@ -100,5 +98,35 @@ public interface ToXContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class DelegatingMapParams extends MapParams {
|
||||||
|
|
||||||
|
private final Params delegate;
|
||||||
|
|
||||||
|
public DelegatingMapParams(Map<String, String> params, Params delegate) {
|
||||||
|
super(params);
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String param(String key) {
|
||||||
|
return super.param(key, delegate.param(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String param(String key, String defaultValue) {
|
||||||
|
return super.param(key, delegate.param(key, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean paramAsBoolean(String key, boolean defaultValue) {
|
||||||
|
return super.paramAsBoolean(key, delegate.paramAsBoolean(key, defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean paramAsBooleanOptional(String key, Boolean defaultValue) {
|
||||||
|
return super.paramAsBooleanOptional(key, delegate.paramAsBooleanOptional(key, defaultValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException;
|
XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package org.elasticsearch.rest.action.admin.indices.template.get;
|
package org.elasticsearch.rest.action.admin.indices.template.get;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||||
@ -26,13 +27,11 @@ import org.elasticsearch.client.Client;
|
|||||||
import org.elasticsearch.client.Requests;
|
import org.elasticsearch.client.Requests;
|
||||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.common.compress.CompressedString;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
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.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
import org.elasticsearch.rest.action.support.RestXContentBuilder;
|
||||||
|
|
||||||
@ -71,39 +70,17 @@ public class RestGetIndexTemplateAction extends BaseRestHandler {
|
|||||||
client.admin().cluster().state(clusterStateRequest, new ActionListener<ClusterStateResponse>() {
|
client.admin().cluster().state(clusterStateRequest, new ActionListener<ClusterStateResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(ClusterStateResponse response) {
|
public void onResponse(ClusterStateResponse response) {
|
||||||
|
Map<String, String> paramsMap = Maps.newHashMap();
|
||||||
|
paramsMap.put("reduce_mappings", "true");
|
||||||
|
ToXContent.Params params = new ToXContent.DelegatingMapParams(paramsMap, request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetaData metaData = response.getState().metaData();
|
MetaData metaData = response.getState().metaData();
|
||||||
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
||||||
for (IndexTemplateMetaData indexMetaData : metaData.templates().values()) {
|
for (IndexTemplateMetaData indexMetaData : metaData.templates().values()) {
|
||||||
builder.startObject(indexMetaData.name(), XContentBuilder.FieldCaseConversion.NONE);
|
IndexTemplateMetaData.Builder.toXContent(indexMetaData, builder, params);
|
||||||
|
|
||||||
builder.field("template", indexMetaData.template());
|
|
||||||
builder.field("order", indexMetaData.order());
|
|
||||||
|
|
||||||
builder.startObject("settings");
|
|
||||||
Settings settings = settingsFilter.filterSettings(indexMetaData.settings());
|
|
||||||
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
|
||||||
builder.field(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
|
|
||||||
builder.startObject("mappings");
|
|
||||||
for (Map.Entry<String, CompressedString> entry : indexMetaData.mappings().entrySet()) {
|
|
||||||
byte[] mappingSource = entry.getValue().uncompressed();
|
|
||||||
XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
|
|
||||||
Map<String, Object> mapping = parser.map();
|
|
||||||
if (mapping.size() == 1 && mapping.containsKey(entry.getKey())) {
|
|
||||||
// the type name is the root value, reduce it
|
|
||||||
mapping = (Map<String, Object>) mapping.get(entry.getKey());
|
|
||||||
}
|
|
||||||
builder.field(entry.getKey());
|
|
||||||
builder.map(mapping);
|
|
||||||
}
|
|
||||||
builder.endObject();
|
|
||||||
|
|
||||||
builder.endObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user