mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Convert FieldCapabilitiesResponse to a ToXContentObject. (#30182)
This commit is contained in:
parent
dd666599f7
commit
d633130e1b
@ -26,7 +26,7 @@ import org.elasticsearch.common.collect.Tuple;
|
|||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
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.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentParserUtils;
|
import org.elasticsearch.common.xcontent.XContentParserUtils;
|
||||||
@ -41,7 +41,7 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* Response for {@link FieldCapabilitiesRequest} requests.
|
* Response for {@link FieldCapabilitiesRequest} requests.
|
||||||
*/
|
*/
|
||||||
public class FieldCapabilitiesResponse extends ActionResponse implements ToXContentFragment {
|
public class FieldCapabilitiesResponse extends ActionResponse implements ToXContentObject {
|
||||||
private static final ParseField FIELDS_FIELD = new ParseField("fields");
|
private static final ParseField FIELDS_FIELD = new ParseField("fields");
|
||||||
|
|
||||||
private Map<String, Map<String, FieldCapabilities>> responseMap;
|
private Map<String, Map<String, FieldCapabilities>> responseMap;
|
||||||
@ -123,8 +123,9 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field(FIELDS_FIELD.getPreferredName(), responseMap);
|
return builder.startObject()
|
||||||
return builder;
|
.field(FIELDS_FIELD.getPreferredName(), responseMap)
|
||||||
|
.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FieldCapabilitiesResponse fromXContent(XContentParser parser) throws IOException {
|
public static FieldCapabilitiesResponse fromXContent(XContentParser parser) throws IOException {
|
||||||
|
@ -81,17 +81,6 @@ public class RestFieldCapabilitiesAction extends BaseRestHandler {
|
|||||||
fieldRequest.indicesOptions(
|
fieldRequest.indicesOptions(
|
||||||
IndicesOptions.fromRequest(request, fieldRequest.indicesOptions())
|
IndicesOptions.fromRequest(request, fieldRequest.indicesOptions())
|
||||||
);
|
);
|
||||||
return channel -> client.fieldCaps(fieldRequest,
|
return channel -> client.fieldCaps(fieldRequest, new RestToXContentListener<>(channel));
|
||||||
new RestBuilderListener<FieldCapabilitiesResponse>(channel) {
|
|
||||||
@Override
|
|
||||||
public RestResponse buildResponse(FieldCapabilitiesResponse response,
|
|
||||||
XContentBuilder builder) throws Exception {
|
|
||||||
RestStatus status = OK;
|
|
||||||
builder.startObject();
|
|
||||||
response.toXContent(builder, request);
|
|
||||||
builder.endObject();
|
|
||||||
return new BytesRestResponse(status, builder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,10 +110,8 @@ public class FieldCapabilitiesResponseTests extends AbstractStreamableXContentTe
|
|||||||
public void testToXContent() throws IOException {
|
public void testToXContent() throws IOException {
|
||||||
FieldCapabilitiesResponse response = createSimpleResponse();
|
FieldCapabilitiesResponse response = createSimpleResponse();
|
||||||
|
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)
|
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||||
.startObject();
|
|
||||||
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
builder.endObject();
|
|
||||||
|
|
||||||
String generatedResponse = BytesReference.bytes(builder).utf8ToString();
|
String generatedResponse = BytesReference.bytes(builder).utf8ToString();
|
||||||
assertEquals((
|
assertEquals((
|
||||||
|
Loading…
x
Reference in New Issue
Block a user