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

Removes types from mapping APIs #2238

Merged
merged 1 commit into from
Feb 24, 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 @@ -127,12 +127,9 @@
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.rest.RestStatus;
import org.opensearch.rest.action.admin.indices.RestCreateIndexAction;
import org.opensearch.rest.action.admin.indices.RestGetFieldMappingAction;
import org.opensearch.rest.action.admin.indices.RestGetIndexTemplateAction;
import org.opensearch.rest.action.admin.indices.RestGetIndicesAction;
import org.opensearch.rest.action.admin.indices.RestGetMappingAction;
import org.opensearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.opensearch.rest.action.admin.indices.RestPutMappingAction;
import org.opensearch.rest.action.admin.indices.RestRolloverIndexAction;

import java.io.IOException;
Expand Down Expand Up @@ -581,32 +578,6 @@ public void testPutMapping() throws IOException {
assertEquals("text", XContentMapValues.extractValue(indexName + ".mappings.properties.field.type", getIndexResponse));
}

public void testPutMappingWithTypes() throws IOException {
String indexName = "mapping_index";
createIndex(indexName, Settings.EMPTY);

org.opensearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest =
new org.opensearch.action.admin.indices.mapping.put.PutMappingRequest(indexName);
putMappingRequest.type("some_type");

XContentBuilder mappingBuilder = JsonXContent.contentBuilder();
mappingBuilder.startObject().startObject("properties").startObject("field");
mappingBuilder.field("type", "text");
mappingBuilder.endObject().endObject().endObject();
putMappingRequest.source(mappingBuilder);

AcknowledgedResponse putMappingResponse = execute(
putMappingRequest,
highLevelClient().indices()::putMapping,
highLevelClient().indices()::putMappingAsync,
expectWarningsOnce(RestPutMappingAction.TYPES_DEPRECATION_MESSAGE)
);
assertTrue(putMappingResponse.isAcknowledged());

Map<String, Object> getIndexResponse = getAsMap(indexName);
assertEquals("text", XContentMapValues.extractValue(indexName + ".mappings.properties.field.type", getIndexResponse));
}

public void testGetMapping() throws IOException {
String indexName = "test";
createIndex(indexName, Settings.EMPTY);
Expand Down Expand Up @@ -646,47 +617,6 @@ public void testGetMapping() throws IOException {
assertThat(mappings, equalTo(expected));
}

public void testGetMappingWithTypes() throws IOException {
String indexName = "test";
createIndex(indexName, Settings.EMPTY);

PutMappingRequest putMappingRequest = new PutMappingRequest(indexName);
XContentBuilder mappingBuilder = JsonXContent.contentBuilder();
mappingBuilder.startObject().startObject("properties").startObject("field");
mappingBuilder.field("type", "text");
mappingBuilder.endObject().endObject().endObject();
putMappingRequest.source(mappingBuilder);

AcknowledgedResponse putMappingResponse = execute(
putMappingRequest,
highLevelClient().indices()::putMapping,
highLevelClient().indices()::putMappingAsync
);
assertTrue(putMappingResponse.isAcknowledged());

Map<String, Object> getIndexResponse = getAsMap(indexName);
assertEquals("text", XContentMapValues.extractValue(indexName + ".mappings.properties.field.type", getIndexResponse));

org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest request =
new org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest().indices(indexName);

org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse getMappingsResponse = execute(
request,
highLevelClient().indices()::getMapping,
highLevelClient().indices()::getMappingAsync,
expectWarningsOnce(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE)
);

Map<String, Object> mappings = getMappingsResponse.getMappings().get(indexName).get("_doc").sourceAsMap();
Map<String, String> type = new HashMap<>();
type.put("type", "text");
Map<String, Object> field = new HashMap<>();
field.put("field", type);
Map<String, Object> expected = new HashMap<>();
expected.put("properties", field);
assertThat(mappings, equalTo(expected));
}

public void testGetFieldMapping() throws IOException {
String indexName = "test";
createIndex(indexName, Settings.EMPTY);
Expand Down Expand Up @@ -723,45 +653,6 @@ public void testGetFieldMapping() throws IOException {
assertThat(fieldMappingMap, equalTo(Collections.singletonMap("field", metadata)));
}

public void testGetFieldMappingWithTypes() throws IOException {
String indexName = "test";
createIndex(indexName, Settings.EMPTY);

PutMappingRequest putMappingRequest = new PutMappingRequest(indexName);
XContentBuilder mappingBuilder = JsonXContent.contentBuilder();
mappingBuilder.startObject().startObject("properties").startObject("field");
mappingBuilder.field("type", "text");
mappingBuilder.endObject().endObject().endObject();
putMappingRequest.source(mappingBuilder);

AcknowledgedResponse putMappingResponse = execute(
putMappingRequest,
highLevelClient().indices()::putMapping,
highLevelClient().indices()::putMappingAsync
);
assertTrue(putMappingResponse.isAcknowledged());

org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest =
new org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsRequest().indices(indexName).types("_doc").fields("field");

org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse getFieldMappingsResponse = execute(
getFieldMappingsRequest,
highLevelClient().indices()::getFieldMapping,
highLevelClient().indices()::getFieldMappingAsync,
expectWarningsOnce(RestGetFieldMappingAction.TYPES_DEPRECATION_MESSAGE)
);

final Map<String, org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata> fieldMappingMap =
getFieldMappingsResponse.mappings().get(indexName).get("_doc");

final org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata metadata =
new org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata(
"field",
new BytesArray("{\"field\":{\"type\":\"text\"}}")
);
assertThat(fieldMappingMap, equalTo(Collections.singletonMap("field", metadata)));
}

public void testDeleteIndex() throws IOException {
{
// Delete index if exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,6 @@ public void testIndexExists() throws IOException {
headTestCase("/test", singletonMap("pretty", "true"), greaterThan(0));
}

public void testTypeExists() throws IOException {
createTestDoc();
headTestCase(
"/test/_mapping/_doc",
emptyMap(),
OK.getStatus(),
greaterThan(0),
"Type exists requests are deprecated, as types have been deprecated."
);
headTestCase(
"/test/_mapping/_doc",
singletonMap("pretty", "true"),
OK.getStatus(),
greaterThan(0),
"Type exists requests are deprecated, as types have been deprecated."
);
}

public void testTypeDoesNotExist() throws IOException {
createTestDoc();
headTestCase(
"/test/_mapping/does-not-exist",
emptyMap(),
NOT_FOUND.getStatus(),
greaterThan(0),
"Type exists requests are deprecated, as types have been deprecated."
);
headTestCase(
"/text/_mapping/test,does-not-exist",
emptyMap(),
NOT_FOUND.getStatus(),
greaterThan(0),
"Type exists requests are deprecated, as types have been deprecated."
);
}

public void testAliasExists() throws IOException {
createTestDoc();
try (XContentBuilder builder = jsonBuilder()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,6 @@
"description":"A comma-separated list of fields"
}
}
},
{
"path":"/_mapping/{type}/field/{fields}",
"methods":[
"GET"
],
"parts":{
"type":{
"type":"list",
"description":"A comma-separated list of document types",
"deprecated":true
},
"fields":{
"type":"list",
"description":"A comma-separated list of fields"
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/{index}/_mapping/{type}/field/{fields}",
"methods":[
"GET"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names"
},
"type":{
"type":"list",
"description":"A comma-separated list of document types",
"deprecated":true
},
"fields":{
"type":"list",
"description":"A comma-separated list of fields"
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,10 @@
"description":"A comma-separated list of index names"
}
}
},
{
"path":"/_mapping/{type}",
"methods":[
"GET"
],
"parts":{
"type":{
"type":"list",
"description":"A comma-separated list of document types",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/{index}/_mapping/{type}",
"methods":[
"GET"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names"
},
"type":{
"type":"list",
"description":"A comma-separated list of document types",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
}
]
},
"params":{
"include_type_name":{
"type":"boolean",
"description":"Whether to add the type name to the response (default: false)"
},
"ignore_unavailable":{
"type":"boolean",
"description":"Whether specified concrete indices should be ignored when unavailable (missing or closed)"
Expand Down
Loading