Search in sources :

Example 1 with GetMappingsRequest

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);
}
Also used : GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest)

Example 2 with GetMappingsRequest

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)));
        }
    });
}
Also used : TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) ActionRunnable(org.opensearch.action.ActionRunnable) RestRequest(org.opensearch.rest.RestRequest) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) RestStatus(org.opensearch.rest.RestStatus) GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) RestActionListener(org.opensearch.rest.action.RestActionListener) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) BytesRestResponse(org.opensearch.rest.BytesRestResponse) GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) TimeValue(org.opensearch.common.unit.TimeValue) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)

Aggregations

GetMappingsRequest (org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest)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 OpenSearchTimeoutException (org.opensearch.OpenSearchTimeoutException)1 ActionRunnable (org.opensearch.action.ActionRunnable)1 GetMappingsResponse (org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 NodeClient (org.opensearch.client.node.NodeClient)1 Strings (org.opensearch.common.Strings)1 TimeValue (org.opensearch.common.unit.TimeValue)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 RestStatus (org.opensearch.rest.RestStatus)1 RestActionListener (org.opensearch.rest.action.RestActionListener)1