Search in sources :

Example 1 with PUT

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));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) RestRequest(org.opensearch.rest.RestRequest) PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) Requests.putMappingRequest(org.opensearch.client.Requests.putMappingRequest) Strings(org.opensearch.common.Strings) XContentHelper(org.opensearch.common.xcontent.XContentHelper) List(java.util.List) MapperService(org.opensearch.index.mapper.MapperService) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BaseRestHandler(org.opensearch.rest.BaseRestHandler) PUT(org.opensearch.rest.RestRequest.Method.PUT) PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest)

Aggregations

IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 Map (java.util.Map)1 PutMappingRequest (org.opensearch.action.admin.indices.mapping.put.PutMappingRequest)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 Requests.putMappingRequest (org.opensearch.client.Requests.putMappingRequest)1 NodeClient (org.opensearch.client.node.NodeClient)1 Strings (org.opensearch.common.Strings)1 XContentHelper (org.opensearch.common.xcontent.XContentHelper)1 MapperService (org.opensearch.index.mapper.MapperService)1 BaseRestHandler (org.opensearch.rest.BaseRestHandler)1 RestRequest (org.opensearch.rest.RestRequest)1 POST (org.opensearch.rest.RestRequest.Method.POST)1 PUT (org.opensearch.rest.RestRequest.Method.PUT)1 RestToXContentListener (org.opensearch.rest.action.RestToXContentListener)1