mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-01 16:39:11 +00:00
turn GetFieldMappingsResponse to ToXContentObject (#31544)
This commit is contained in:
parent
e6dc01d2b7
commit
6be94dbecd
@ -28,6 +28,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
||||||
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
@ -47,7 +48,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||||||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
||||||
|
|
||||||
/** Response object for {@link GetFieldMappingsRequest} API */
|
/** Response object for {@link GetFieldMappingsRequest} API */
|
||||||
public class GetFieldMappingsResponse extends ActionResponse implements ToXContentFragment {
|
public class GetFieldMappingsResponse extends ActionResponse implements ToXContentObject {
|
||||||
|
|
||||||
private static final ParseField MAPPINGS = new ParseField("mappings");
|
private static final ParseField MAPPINGS = new ParseField("mappings");
|
||||||
|
|
||||||
@ -111,6 +112,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
builder.startObject();
|
||||||
for (Map.Entry<String, Map<String, Map<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
|
for (Map.Entry<String, Map<String, Map<String, FieldMappingMetaData>>> indexEntry : mappings.entrySet()) {
|
||||||
builder.startObject(indexEntry.getKey());
|
builder.startObject(indexEntry.getKey());
|
||||||
builder.startObject(MAPPINGS.getPreferredName());
|
builder.startObject(MAPPINGS.getPreferredName());
|
||||||
@ -126,6 +128,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
|
|||||||
builder.endObject();
|
builder.endObject();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,9 +81,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
|
|||||||
if (mappingsByIndex.isEmpty() && fields.length > 0) {
|
if (mappingsByIndex.isEmpty() && fields.length > 0) {
|
||||||
status = NOT_FOUND;
|
status = NOT_FOUND;
|
||||||
}
|
}
|
||||||
builder.startObject();
|
|
||||||
response.toXContent(builder, request);
|
response.toXContent(builder, request);
|
||||||
builder.endObject();
|
|
||||||
return new BytesRestResponse(status, builder);
|
return new BytesRestResponse(status, builder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -149,9 +149,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
|||||||
params.put("pretty", "true");
|
params.put("pretty", "true");
|
||||||
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
|
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
|
||||||
XContentBuilder responseBuilder = XContentFactory.jsonBuilder().prettyPrint();
|
XContentBuilder responseBuilder = XContentFactory.jsonBuilder().prettyPrint();
|
||||||
responseBuilder.startObject();
|
|
||||||
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
|
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
|
||||||
responseBuilder.endObject();
|
|
||||||
String responseStrings = Strings.toString(responseBuilder);
|
String responseStrings = Strings.toString(responseBuilder);
|
||||||
|
|
||||||
|
|
||||||
@ -163,9 +161,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
|||||||
|
|
||||||
response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
|
response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
|
||||||
responseBuilder = XContentFactory.jsonBuilder().prettyPrint().lfAtEnd();
|
responseBuilder = XContentFactory.jsonBuilder().prettyPrint().lfAtEnd();
|
||||||
responseBuilder.startObject();
|
|
||||||
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
|
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
|
||||||
responseBuilder.endObject();
|
|
||||||
responseStrings = Strings.toString(responseBuilder);
|
responseStrings = Strings.toString(responseBuilder);
|
||||||
|
|
||||||
prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
|
prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user