Search in sources :

Example 1 with GetFieldMappingsRequest

use of org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest in project OpenSearch by opensearch-project.

the class IndicesRequestIT method testGetFieldMappings.

public void testGetFieldMappings() {
    String getFieldMappingsShardAction = GetFieldMappingsAction.NAME + "[index][s]";
    interceptTransportActions(getFieldMappingsShardAction);
    GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest();
    getFieldMappingsRequest.indices(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().getFieldMappings(getFieldMappingsRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(getFieldMappingsRequest, getFieldMappingsShardAction);
}
Also used : GetFieldMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest)

Example 2 with GetFieldMappingsRequest

use of org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest in project OpenSearch by opensearch-project.

the class RestGetFieldMappingAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] fields = Strings.splitStringByCommaToArray(request.param("fields"));
    GetFieldMappingsRequest getMappingsRequest = new GetFieldMappingsRequest();
    getMappingsRequest.indices(indices).fields(fields).includeDefaults(request.paramAsBoolean("include_defaults", false));
    getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
    if (request.hasParam("local")) {
        deprecationLogger.deprecate("get_field_mapping_local", "Use [local] in get field mapping requests is deprecated. " + "The parameter will be removed in the next major version");
    }
    getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
    return channel -> client.admin().indices().getFieldMappings(getMappingsRequest, new RestBuilderListener<GetFieldMappingsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBuilder builder) throws Exception {
            Map<String, Map<String, Map<String, FieldMappingMetadata>>> mappingsByIndex = response.mappings();
            boolean isPossibleSingleFieldRequest = indices.length == 1 && fields.length == 1;
            if (isPossibleSingleFieldRequest && isFieldMappingMissingField(mappingsByIndex)) {
                return new BytesRestResponse(OK, builder.startObject().endObject());
            }
            RestStatus status = OK;
            if (mappingsByIndex.isEmpty() && fields.length > 0) {
                status = NOT_FOUND;
            }
            response.toXContent(builder, request);
            return new BytesRestResponse(status, builder);
        }
    });
}
Also used : OK(org.opensearch.rest.RestStatus.OK) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) GetFieldMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest) IOException(java.io.IOException) FieldMappingMetadata(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata) IndicesOptions(org.opensearch.action.support.IndicesOptions) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) NOT_FOUND(org.opensearch.rest.RestStatus.NOT_FOUND) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) Logger(org.apache.logging.log4j.Logger) GetFieldMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BaseRestHandler(org.opensearch.rest.BaseRestHandler) LogManager(org.apache.logging.log4j.LogManager) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) GetFieldMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest) GetFieldMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) Map(java.util.Map) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

GetFieldMappingsRequest (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest)2 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 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 GetFieldMappingsResponse (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse)1 FieldMappingMetadata (org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 NodeClient (org.opensearch.client.node.NodeClient)1 Strings (org.opensearch.common.Strings)1 DeprecationLogger (org.opensearch.common.logging.DeprecationLogger)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 BaseRestHandler (org.opensearch.rest.BaseRestHandler)1 BytesRestResponse (org.opensearch.rest.BytesRestResponse)1 RestRequest (org.opensearch.rest.RestRequest)1 GET (org.opensearch.rest.RestRequest.Method.GET)1 RestResponse (org.opensearch.rest.RestResponse)1