Search in sources :

Example 1 with PutMappingRequest

use of org.opensearch.action.admin.indices.mapping.put.PutMappingRequest in project OpenSearch by opensearch-project.

the class IndicesRequestIT method testPutMapping.

public void testPutMapping() {
    interceptTransportActions(PutMappingAction.NAME);
    PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).source("field", "type=text");
    internalCluster().coordOnlyNodeClient().admin().indices().putMapping(putMappingRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(putMappingRequest, PutMappingAction.NAME);
}
Also used : PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest)

Example 2 with PutMappingRequest

use of org.opensearch.action.admin.indices.mapping.put.PutMappingRequest in project OpenSearch by opensearch-project.

the class UpdateMappingTests method testMappingVersion.

public void testMappingVersion() {
    createIndex("test", client().admin().indices().prepareCreate("test").addMapping("type"));
    final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
    {
        final long previousVersion = clusterService.state().metadata().index("test").getMappingVersion();
        final PutMappingRequest request = new PutMappingRequest();
        request.indices("test");
        request.source("field", "type=text");
        client().admin().indices().putMapping(request).actionGet();
        assertThat(clusterService.state().metadata().index("test").getMappingVersion(), Matchers.equalTo(1 + previousVersion));
    }
    {
        final long previousVersion = clusterService.state().metadata().index("test").getMappingVersion();
        final PutMappingRequest request = new PutMappingRequest();
        request.indices("test");
        request.source("field", "type=text");
        client().admin().indices().putMapping(request).actionGet();
        // the version should be unchanged after putting the same mapping again
        assertThat(clusterService.state().metadata().index("test").getMappingVersion(), Matchers.equalTo(previousVersion));
    }
}
Also used : ClusterService(org.opensearch.cluster.service.ClusterService) PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest)

Example 3 with PutMappingRequest

use of org.opensearch.action.admin.indices.mapping.put.PutMappingRequest 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)

Example 4 with PutMappingRequest

use of org.opensearch.action.admin.indices.mapping.put.PutMappingRequest in project OpenSearch by opensearch-project.

the class MappingUpdatedAction method sendUpdateMapping.

// can be overridden by tests
protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListener<Void> listener) {
    PutMappingRequest putMappingRequest = new PutMappingRequest();
    putMappingRequest.setConcreteIndex(index);
    putMappingRequest.source(mappingUpdate.toString(), XContentType.JSON);
    putMappingRequest.masterNodeTimeout(dynamicMappingUpdateTimeout);
    putMappingRequest.timeout(TimeValue.ZERO);
    if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(LegacyESVersion.V_7_9_0)) {
        client.execute(AutoPutMappingAction.INSTANCE, putMappingRequest, ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure));
    } else {
        client.putMapping(putMappingRequest, ActionListener.wrap(r -> listener.onResponse(null), e -> listener.onFailure(unwrapException(e))));
    }
}
Also used : Client(org.opensearch.client.Client) Setting(org.opensearch.common.settings.Setting) TimeValue(org.opensearch.common.unit.TimeValue) Index(org.opensearch.index.Index) Semaphore(java.util.concurrent.Semaphore) PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest) AutoPutMappingAction(org.opensearch.action.admin.indices.mapping.put.AutoPutMappingAction) Settings(org.opensearch.common.settings.Settings) OpenSearchException(org.opensearch.OpenSearchException) RunOnce(org.opensearch.common.util.concurrent.RunOnce) UncategorizedExecutionException(org.opensearch.common.util.concurrent.UncategorizedExecutionException) MasterNodeRequest(org.opensearch.action.support.master.MasterNodeRequest) LegacyESVersion(org.opensearch.LegacyESVersion) Mapping(org.opensearch.index.mapper.Mapping) IndicesAdminClient(org.opensearch.client.IndicesAdminClient) Property(org.opensearch.common.settings.Setting.Property) ClusterService(org.opensearch.cluster.service.ClusterService) Inject(org.opensearch.common.inject.Inject) XContentType(org.opensearch.common.xcontent.XContentType) ActionListener(org.opensearch.action.ActionListener) ClusterSettings(org.opensearch.common.settings.ClusterSettings) PutMappingRequest(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest)

Aggregations

PutMappingRequest (org.opensearch.action.admin.indices.mapping.put.PutMappingRequest)4 ClusterService (org.opensearch.cluster.service.ClusterService)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 Semaphore (java.util.concurrent.Semaphore)1 LegacyESVersion (org.opensearch.LegacyESVersion)1 OpenSearchException (org.opensearch.OpenSearchException)1 ActionListener (org.opensearch.action.ActionListener)1 AutoPutMappingAction (org.opensearch.action.admin.indices.mapping.put.AutoPutMappingAction)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 MasterNodeRequest (org.opensearch.action.support.master.MasterNodeRequest)1 Client (org.opensearch.client.Client)1 IndicesAdminClient (org.opensearch.client.IndicesAdminClient)1 Requests.putMappingRequest (org.opensearch.client.Requests.putMappingRequest)1 NodeClient (org.opensearch.client.node.NodeClient)1 Strings (org.opensearch.common.Strings)1 Inject (org.opensearch.common.inject.Inject)1