use of org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest in project OpenSearch by opensearch-project.
the class IndicesRequestIT method testGetMappings.
public void testGetMappings() {
interceptTransportActions(GetMappingsAction.NAME);
GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(randomIndicesOrAliases());
internalCluster().coordOnlyNodeClient().admin().indices().getMappings(getMappingsRequest).actionGet();
clearInterceptedActions();
assertSameIndices(getMappingsRequest, GetMappingsAction.NAME);
}
use of org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest in project OpenSearch by opensearch-project.
the class RestGetMappingAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
getMappingsRequest.indices(indices);
getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
final TimeValue timeout = request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout());
getMappingsRequest.masterNodeTimeout(timeout);
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestActionListener<GetMappingsResponse>(channel) {
@Override
protected void processResponse(GetMappingsResponse getMappingsResponse) {
final long startTimeMs = threadPool.relativeTimeInMillis();
// Process serialization on GENERIC pool since the serialization of the raw mappings to XContent can be too slow to execute
// on an IO thread
threadPool.executor(ThreadPool.Names.MANAGEMENT).execute(ActionRunnable.wrap(this, l -> new RestBuilderListener<GetMappingsResponse>(channel) {
@Override
public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {
if (threadPool.relativeTimeInMillis() - startTimeMs > timeout.millis()) {
throw new OpenSearchTimeoutException("Timed out getting mappings");
}
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
}.onResponse(getMappingsResponse)));
}
});
}
Aggregations