use of org.opensearch.rest.RestRequest.Method.PUT in project OpenSearch by opensearch-project.
the class RestPutMappingAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2();
if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap)) {
throw new IllegalArgumentException("Types cannot be provided in put mapping requests");
}
putMappingRequest.source(sourceAsMap);
putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout()));
putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout()));
putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions()));
putMappingRequest.writeIndexOnly(request.paramAsBoolean("write_index_only", false));
return channel -> client.admin().indices().putMapping(putMappingRequest, new RestToXContentListener<>(channel));
}
Aggregations