Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remove] types from PutMappingRequest #2335

Merged
merged 9 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -456,59 +456,6 @@ public Cancellable putMappingAsync(
);
}

/**
* Updates the mappings on an index using the Put Mapping API.
*
* @param putMappingRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
* {@link #putMapping(PutMappingRequest, RequestOptions)} should be used instead, which accepts a new request object.
*/
@Deprecated
public AcknowledgedResponse putMapping(
org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest,
RequestOptions options
) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
putMappingRequest,
IndicesRequestConverters::putMapping,
options,
AcknowledgedResponse::fromXContent,
emptySet()
);
}

/**
* Asynchronously updates the mappings on an index using the Put Mapping API.
*
* @param putMappingRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
* method {@link #putMappingAsync(PutMappingRequest, RequestOptions, ActionListener)} should be used instead,
* which accepts a new request object.
* @return cancellable that may be used to cancel the request
*/
@Deprecated
public Cancellable putMappingAsync(
org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest,
RequestOptions options,
ActionListener<AcknowledgedResponse> listener
) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
putMappingRequest,
IndicesRequestConverters::putMapping,
options,
AcknowledgedResponse::fromXContent,
listener,
emptySet()
);
}

/**
Copy link
Member

@dreamer-89 dreamer-89 Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are other deprecated methods e.g. getFieldMapping, getFieldMappingAsync etc; also under your radar for removal ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Upcoming PR

* Retrieves the mappings on an index or indices using the Get Mapping API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,31 +202,6 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio
return request;
}

/**
* converter for the legacy server-side {@link org.opensearch.action.admin.indices.mapping.put.PutMappingRequest} that still supports
* types
*/
@Deprecated
static Request putMapping(org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) throws IOException {
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
if (putMappingRequest.getConcreteIndex() != null) {
throw new IllegalArgumentException("concreteIndex cannot be set on PutMapping requests made over the REST API");
}

Request request = new Request(
HttpPut.METHOD_NAME,
RequestConverters.endpoint(putMappingRequest.indices(), "_mapping", putMappingRequest.type())
);

RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withTimeout(putMappingRequest.timeout());
parameters.withMasterTimeout(putMappingRequest.masterNodeTimeout());
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
request.addParameters(parameters.asMap());
request.setEntity(RequestConverters.createEntity(putMappingRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request getMappings(GetMappingsRequest getMappingsRequest) {
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1594,38 +1594,6 @@ public void testIndexPutSettingNonExistent() throws IOException {
);
}

@SuppressWarnings("unchecked")
public void testPutTemplateWithTypes() throws Exception {
org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequest putTemplateRequest =
new org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequest().name("my-template")
.patterns(Arrays.asList("pattern-1", "name-*"))
.order(10)
.create(randomBoolean())
.settings(Settings.builder().put("number_of_shards", "3").put("number_of_replicas", "0"))
.mapping("doc", "host_name", "type=keyword", "description", "type=text")
.alias(new Alias("alias-1").indexRouting("abc"))
.alias(new Alias("{index}-write").searchRouting("xyz"));

AcknowledgedResponse putTemplateResponse = execute(
putTemplateRequest,
highLevelClient().indices()::putTemplate,
highLevelClient().indices()::putTemplateAsync,
expectWarningsOnce(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)
);
assertThat(putTemplateResponse.isAcknowledged(), equalTo(true));

Map<String, Object> templates = getAsMap("/_template/my-template");
assertThat(templates.keySet(), hasSize(1));
assertThat(extractValue("my-template.order", templates), equalTo(10));
assertThat(extractRawValues("my-template.index_patterns", templates), contains("pattern-1", "name-*"));
assertThat(extractValue("my-template.settings.index.number_of_shards", templates), equalTo("3"));
assertThat(extractValue("my-template.settings.index.number_of_replicas", templates), equalTo("0"));
assertThat(extractValue("my-template.mappings.properties.host_name.type", templates), equalTo("keyword"));
assertThat(extractValue("my-template.mappings.properties.description.type", templates), equalTo("text"));
assertThat((Map<String, String>) extractValue("my-template.aliases.alias-1", templates), hasEntry("index_routing", "abc"));
assertThat((Map<String, String>) extractValue("my-template.aliases.{index}-write", templates), hasEntry("search_routing", "xyz"));
}

@SuppressWarnings("unchecked")
public void testPutTemplate() throws Exception {
PutIndexTemplateRequest putTemplateRequest = new PutIndexTemplateRequest("my-template").patterns(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,37 +254,6 @@ public void testPutMapping() throws IOException {
RequestConvertersTests.assertToXContentBody(putMappingRequest, request.getEntity());
}

public void testPutMappingWithTypes() throws IOException {
org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest =
new org.opensearch.action.admin.indices.mapping.put.PutMappingRequest();

String[] indices = RequestConvertersTests.randomIndicesNames(0, 5);
putMappingRequest.indices(indices);

String type = OpenSearchTestCase.randomAlphaOfLengthBetween(3, 10);
putMappingRequest.type(type);

Map<String, String> expectedParams = new HashMap<>();

RequestConvertersTests.setRandomTimeout(putMappingRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
RequestConvertersTests.setRandomMasterTimeout(putMappingRequest, expectedParams);
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");

Request request = IndicesRequestConverters.putMapping(putMappingRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add("_mapping");
endpoint.add(type);
Assert.assertEquals(endpoint.toString(), request.getEndpoint());

Assert.assertEquals(expectedParams, request.getParameters());
Assert.assertEquals(HttpPut.METHOD_NAME, request.getMethod());
RequestConvertersTests.assertToXContentBody(putMappingRequest, request.getEntity());
}

public void testGetMapping() {
GetMappingsRequest getMappingRequest = new GetMappingsRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
"_doc",
"my_feature_field",
"type=rank_feature",
"my_negative_feature_field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,14 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
docType,
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
docType,
queryField,
"type=percolator",
aliasField,
"type=alias,path=" + queryField
)
PutMappingRequest.buildFromSimplifiedDef(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField)
)
),
MapperService.MergeReason.MAPPING_UPDATE
);
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(docType, TEXT_FIELD_NAME, "type=text"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(TEXT_FIELD_NAME, "type=text"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
super.initializeAdditionalMappings(mapperService);
mapperService.merge(
"_doc",
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc", "some_nested_object", "type=nested"))),
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("some_nested_object", "type=nested"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testUpdateByQuery() {
Client client = client();
client.admin().indices().prepareCreate("foo").get();
client.admin().indices().prepareCreate("bar").get();
client.admin().indices().preparePutMapping(INDEX_NAME).setType("_doc").setSource("cat", "type=keyword").get();
client.admin().indices().preparePutMapping(INDEX_NAME).setSource("cat", "type=keyword").get();
{
// tag::update-by-query
UpdateByQueryRequestBuilder updateByQuery =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.plugin.mapper.MapperSizePlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
Expand All @@ -62,7 +63,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
// issue 5053
public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() throws Exception {
String index = "foo";
String type = "mytype";
String type = MapperService.SINGLE_MAPPING_NAME;

XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
Expand All @@ -78,12 +79,7 @@ public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() thr
.endObject()
.endObject()
.endObject();
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping(index)
.setType(type)
.setSource(updateMappingBuilder)
.get();
AcknowledgedResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);

// make sure size field is still in mapping
Expand All @@ -92,7 +88,7 @@ public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() thr

public void testThatSizeCanBeSwitchedOnAndOff() throws Exception {
String index = "foo";
String type = "mytype";
String type = MapperService.SINGLE_MAPPING_NAME;

XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
Expand All @@ -106,12 +102,7 @@ public void testThatSizeCanBeSwitchedOnAndOff() throws Exception {
.field("enabled", false)
.endObject()
.endObject();
AcknowledgedResponse putMappingResponse = client().admin()
.indices()
.preparePutMapping(index)
.setType(type)
.setSource(updateMappingBuilder)
.get();
AcknowledgedResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);

// make sure size field is still in mapping
Expand All @@ -133,7 +124,7 @@ private void assertSizeMappingEnabled(String index, boolean enabled) throws IOEx
}

public void testBasic() throws Exception {
assertAcked(prepareCreate("test").addMapping("type", "_size", "enabled=true"));
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, "_size", "enabled=true"));
final String source = "{\"f\":10}";
indexRandom(true, client().prepareIndex("test").setId("1").setSource(source, XContentType.JSON));
GetResponse getResponse = client().prepareGet("test", "1").setStoredFields("_size").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ public void testGetMappings() {
public void testPutMapping() {
interceptTransportActions(PutMappingAction.NAME);

PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).type("type")
.source("field", "type=text");
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).source("field", "type=text");
internalCluster().coordOnlyNodeClient().admin().indices().putMapping(putMappingRequest).actionGet();

clearInterceptedActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void testTransportBulkTasks() {
createIndex("test");
ensureGreen("test"); // Make sure all shards are allocated to catch replication tasks
// ensures the mapping is available on all nodes so we won't retry the request (in case replicas don't have the right mapping).
client().admin().indices().preparePutMapping("test").setType("doc").setSource("foo", "type=keyword").get();
client().admin().indices().preparePutMapping("test").setSource("foo", "type=keyword").get();
client().prepareBulk().add(client().prepareIndex("test").setId("test_id").setSource("{\"foo\": \"bar\"}", XContentType.JSON)).get();

// the bulk operation should produce one main task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.SegmentsStats;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.shard.IndexShard;
Expand Down Expand Up @@ -526,7 +527,7 @@ public void testCreateShrinkWithIndexSort() throws Exception {
.put("sort.order", "desc")
.put("number_of_shards", 8)
.put("number_of_replicas", 0)
).addMapping("type", "id", "type=keyword,doc_values=true").get();
).addMapping(MapperService.SINGLE_MAPPING_NAME, "id", "type=keyword,doc_values=true").get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source")
.setId(Integer.toString(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.SegmentsStats;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.shard.IndexShard;
Expand Down Expand Up @@ -135,12 +136,12 @@ private void splitToN(int sourceShards, int firstSplitShards, int secondSplitSha
int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, Version.CURRENT) - 1;
settings.put("index.routing_partition_size", randomIntBetween(1, numRoutingShards));
if (useNested) {
createInitialIndex.addMapping("t1", "_routing", "required=true", "nested1", "type=nested");
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "_routing", "required=true", "nested1", "type=nested");
} else {
createInitialIndex.addMapping("t1", "_routing", "required=true");
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "_routing", "required=true");
}
} else if (useNested) {
createInitialIndex.addMapping("t1", "nested1", "type=nested");
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "nested1", "type=nested");
}
logger.info("use routing {} use mixed routing {} use nested {}", useRouting, useMixedRouting, useNested);
createInitialIndex.setSettings(settings).get();
Expand Down Expand Up @@ -522,7 +523,7 @@ public void testCreateSplitWithIndexSort() throws Exception {
.put("sort.order", "desc")
.put("number_of_shards", 2)
.put("number_of_replicas", 0)
).addMapping("type", "id", "type=keyword,doc_values=true").get();
).addMapping(MapperService.SINGLE_MAPPING_NAME, "id", "type=keyword,doc_values=true").get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source")
.setId(Integer.toString(i))
Expand Down
Loading