Removes type mappings from mapping APIs (#2238)

Removes type mappings from GetMapping, GetFieldMapping and PutMapping APIs

Signed-off-by: Suraj Singh <surajrider@gmail.com>
This commit is contained in:
Suraj Singh 2022-02-24 11:23:36 -08:00 committed by GitHub
parent b251d2b565
commit cbfcad9054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 51 additions and 1083 deletions

View File

@ -127,12 +127,9 @@ import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.query.QueryBuilders;
import org.opensearch.rest.RestStatus; import org.opensearch.rest.RestStatus;
import org.opensearch.rest.action.admin.indices.RestCreateIndexAction; 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.RestGetIndexTemplateAction;
import org.opensearch.rest.action.admin.indices.RestGetIndicesAction; 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.RestPutIndexTemplateAction;
import org.opensearch.rest.action.admin.indices.RestPutMappingAction;
import org.opensearch.rest.action.admin.indices.RestRolloverIndexAction; import org.opensearch.rest.action.admin.indices.RestRolloverIndexAction;
import java.io.IOException; import java.io.IOException;
@ -581,32 +578,6 @@ public class IndicesClientIT extends OpenSearchRestHighLevelClientTestCase {
assertEquals("text", XContentMapValues.extractValue(indexName + ".mappings.properties.field.type", getIndexResponse)); 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 { public void testGetMapping() throws IOException {
String indexName = "test"; String indexName = "test";
createIndex(indexName, Settings.EMPTY); createIndex(indexName, Settings.EMPTY);
@ -646,47 +617,6 @@ public class IndicesClientIT extends OpenSearchRestHighLevelClientTestCase {
assertThat(mappings, equalTo(expected)); 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 { public void testGetFieldMapping() throws IOException {
String indexName = "test"; String indexName = "test";
createIndex(indexName, Settings.EMPTY); createIndex(indexName, Settings.EMPTY);
@ -723,45 +653,6 @@ public class IndicesClientIT extends OpenSearchRestHighLevelClientTestCase {
assertThat(fieldMappingMap, equalTo(Collections.singletonMap("field", metadata))); 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 { public void testDeleteIndex() throws IOException {
{ {
// Delete index if exists // Delete index if exists

View File

@ -86,42 +86,6 @@ public class Netty4HeadBodyIsEmptyIT extends OpenSearchRestTestCase {
headTestCase("/test", singletonMap("pretty", "true"), greaterThan(0)); 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 { public void testAliasExists() throws IOException {
createTestDoc(); createTestDoc();
try (XContentBuilder builder = jsonBuilder()) { try (XContentBuilder builder = jsonBuilder()) {

View File

@ -34,52 +34,6 @@
"description":"A comma-separated list of fields" "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"
}
} }
] ]
}, },

View File

@ -24,52 +24,10 @@
"description":"A comma-separated list of index names" "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":{ "params":{
"include_type_name":{
"type":"boolean",
"description":"Whether to add the type name to the response (default: false)"
},
"ignore_unavailable":{ "ignore_unavailable":{
"type":"boolean", "type":"boolean",
"description":"Whether specified concrete indices should be ignored when unavailable (missing or closed)" "description":"Whether specified concrete indices should be ignored when unavailable (missing or closed)"

View File

@ -19,155 +19,10 @@
"description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices." "description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices."
} }
} }
},
{
"path":"/{index}/{type}/_mapping",
"methods":[
"PUT",
"POST"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices."
},
"type":{
"type":"string",
"description":"The name of the document type",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/{index}/_mapping/{type}",
"methods":[
"PUT",
"POST"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices."
},
"type":{
"type":"string",
"description":"The name of the document type",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/{index}/{type}/_mappings",
"methods":[
"PUT",
"POST"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices."
},
"type":{
"type":"string",
"description":"The name of the document type",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/{index}/_mappings/{type}",
"methods":[
"PUT",
"POST"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices."
},
"type":{
"type":"string",
"description":"The name of the document type",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/_mappings/{type}",
"methods":[
"PUT",
"POST"
],
"parts":{
"type":{
"type":"string",
"description":"The name of the document type",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
},
{
"path":"/{index}/_mappings",
"methods":[
"PUT",
"POST"
],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names the mapping should be added to (supports wildcards); use `_all` or omit to add the mapping on all indices."
}
},
"deprecated":{
"version":"7.0.0",
"description":"The plural mappings is accepted but only /_mapping is documented"
}
},
{
"path":"/_mapping/{type}",
"methods":[
"PUT",
"POST"
],
"parts":{
"type":{
"type":"string",
"description":"The name of the document type",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
} }
] ]
}, },
"params":{ "params":{
"include_type_name":{
"type":"boolean",
"description":"Whether a type should be expected in the body of the mappings."
},
"timeout":{ "timeout":{
"type":"time", "type":"time",
"description":"Explicit operation timeout" "description":"Explicit operation timeout"

View File

@ -1,83 +0,0 @@
---
setup:
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
---
"Get field mapping with no index and type":
- do:
indices.get_field_mapping:
include_type_name: true
fields: text
- match: {test_index.mappings.test_type.text.mapping.text.type: text}
---
"Get field mapping by index only":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
fields: text
- match: {test_index.mappings.test_type.text.mapping.text.type: text}
---
"Get field mapping by type & field":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: text
- match: {test_index.mappings.test_type.text.mapping.text.type: text}
---
"Get field mapping by type & field, with another field that doesn't exist":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: [ text , text1 ]
- match: {test_index.mappings.test_type.text.mapping.text.type: text}
- is_false: test_index.mappings.test_type.text1
---
"Get field mapping with include_defaults":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: text
include_defaults: true
- match: {test_index.mappings.test_type.text.mapping.text.type: text}
- match: {test_index.mappings.test_type.text.mapping.text.analyzer: default}
---
"Get field mapping should work without index specifying type and fields":
- do:
indices.get_field_mapping:
include_type_name: true
type: test_type
fields: text
- match: {test_index.mappings.test_type.text.mapping.text.type: text}

View File

@ -1,23 +0,0 @@
---
"Return empty object if field doesn't exist, but type and index do":
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
analyzer: whitespace
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
type: test_type
fields: not_existent
- match: { '': {}}

View File

@ -1,22 +0,0 @@
---
"Raise 404 when type doesn't exist":
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
analyzer: whitespace
- do:
catch: missing
indices.get_field_mapping:
include_type_name: true
index: test_index
type: not_test_type
fields: text

View File

@ -1,144 +0,0 @@
---
setup:
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
t1:
type: text
t2:
type: text
obj:
properties:
t1:
type: text
i_t1:
type: text
i_t3:
type: text
- do:
indices.create:
include_type_name: true
index: test_index_2
body:
mappings:
test_type_2:
properties:
t1:
type: text
t2:
type: text
obj:
properties:
t1:
type: text
i_t1:
type: text
i_t3:
type: text
---
"Get field mapping with * for fields":
- do:
indices.get_field_mapping:
include_type_name: true
fields: "*"
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.t2.full_name: t2 }
- match: {test_index.mappings.test_type.obj\.t1.full_name: obj.t1 }
- match: {test_index.mappings.test_type.obj\.i_t1.full_name: obj.i_t1 }
- match: {test_index.mappings.test_type.obj\.i_t3.full_name: obj.i_t3 }
---
"Get field mapping with t* for fields":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
fields: "t*"
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.t2.full_name: t2 }
- length: {test_index.mappings.test_type: 2}
---
"Get field mapping with *t1 for fields":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
fields: "*t1"
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.obj\.t1.full_name: obj.t1 }
- match: {test_index.mappings.test_type.obj\.i_t1.full_name: obj.i_t1 }
- length: {test_index.mappings.test_type: 3}
---
"Get field mapping with wildcarded relative names":
- do:
indices.get_field_mapping:
include_type_name: true
index: test_index
fields: "obj.i_*"
- match: {test_index.mappings.test_type.obj\.i_t1.full_name: obj.i_t1 }
- match: {test_index.mappings.test_type.obj\.i_t3.full_name: obj.i_t3 }
- length: {test_index.mappings.test_type: 2}
---
"Get field mapping should work using '_all' for indices and types":
- do:
indices.get_field_mapping:
include_type_name: true
index: _all
type: _all
fields: "t*"
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.t2.full_name: t2 }
- length: {test_index.mappings.test_type: 2}
- match: {test_index_2.mappings.test_type_2.t1.full_name: t1 }
- match: {test_index_2.mappings.test_type_2.t2.full_name: t2 }
- length: {test_index_2.mappings.test_type_2: 2}
---
"Get field mapping should work using '*' for indices and types":
- do:
indices.get_field_mapping:
include_type_name: true
index: '*'
type: '*'
fields: "t*"
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.t2.full_name: t2 }
- length: {test_index.mappings.test_type: 2}
- match: {test_index_2.mappings.test_type_2.t1.full_name: t1 }
- match: {test_index_2.mappings.test_type_2.t2.full_name: t2 }
- length: {test_index_2.mappings.test_type_2: 2}
---
"Get field mapping should work using comma_separated values for indices and types":
- do:
indices.get_field_mapping:
include_type_name: true
index: 'test_index,test_index_2'
type: 'test_type,test_type_2'
fields: "t*"
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.t2.full_name: t2 }
- length: {test_index.mappings.test_type: 2}
- match: {test_index_2.mappings.test_type_2.t1.full_name: t1 }
- match: {test_index_2.mappings.test_type_2.t2.full_name: t2 }
- length: {test_index_2.mappings.test_type_2: 2}

View File

@ -1,21 +0,0 @@
---
"GET mapping with typeless API on an index that has types":
- do:
indices.create: # not using include_type_name: false on purpose
include_type_name: true
index: index
body:
mappings:
not_doc:
properties:
foo:
type: "keyword"
- do:
indices.get_field_mapping:
include_type_name: false
index: index
fields: foo
- match: { index.mappings.foo.mapping.foo.type: "keyword" }

View File

@ -1,158 +0,0 @@
---
setup:
- do:
indices.create:
include_type_name: true
index: test_1
body:
mappings:
doc: {}
- do:
indices.create:
include_type_name: true
index: test_2
body:
mappings:
doc: {}
---
"Get /{index}/_mapping with empty mappings":
- do:
indices.create:
index: t
- do:
indices.get_mapping:
include_type_name: true
index: t
- match: { t.mappings: {}}
---
"Get /_mapping":
- do:
indices.get_mapping:
include_type_name: true
- is_true: test_1.mappings.doc
- is_true: test_2.mappings.doc
---
"Get /{index}/_mapping":
- do:
indices.get_mapping:
include_type_name: true
index: test_1
- is_true: test_1.mappings.doc
- is_false: test_2
---
"Get /{index}/_mapping/_all":
- do:
indices.get_mapping:
include_type_name: true
index: test_1
type: _all
- is_true: test_1.mappings.doc
- is_false: test_2
---
"Get /{index}/_mapping/*":
- do:
indices.get_mapping:
include_type_name: true
index: test_1
type: '*'
- is_true: test_1.mappings.doc
- is_false: test_2
---
"Get /{index}/_mapping/{type}":
- do:
indices.get_mapping:
include_type_name: true
index: test_1
type: doc
- is_true: test_1.mappings.doc
- is_false: test_2
---
"Get /{index}/_mapping/{type*}":
- do:
indices.get_mapping:
include_type_name: true
index: test_1
type: 'd*'
- is_true: test_1.mappings.doc
- is_false: test_2
---
"Get /_mapping/{type}":
- do:
indices.get_mapping:
include_type_name: true
type: doc
- is_true: test_1.mappings.doc
- is_true: test_2.mappings.doc
---
"Get /_all/_mapping/{type}":
- do:
indices.get_mapping:
include_type_name: true
index: _all
type: doc
- is_true: test_1.mappings.doc
- is_true: test_2.mappings.doc
---
"Get /*/_mapping/{type}":
- do:
indices.get_mapping:
include_type_name: true
index: '*'
type: doc
- is_true: test_1.mappings.doc
- is_true: test_2.mappings.doc
---
"Get /index,index/_mapping/{type}":
- do:
indices.get_mapping:
include_type_name: true
index: test_1,test_2
type: doc
- is_true: test_1.mappings.doc
- is_true: test_2.mappings.doc
---
"Get /index*/_mapping/{type}":
- do:
indices.get_mapping:
include_type_name: true
index: '*2'
type: doc
- is_true: test_2.mappings.doc
- is_false: test_1

View File

@ -1,106 +0,0 @@
---
"Non-existent type returns 404":
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
analyzer: whitespace
- do:
catch: missing
indices.get_mapping:
include_type_name: true
index: test_index
type: not_test_type
- match: { status: 404 }
- match: { error.reason: 'type[[not_test_type]] missing' }
---
"No type matching pattern returns 404":
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
analyzer: whitespace
- do:
catch: missing
indices.get_mapping:
include_type_name: true
index: test_index
type: test*,not*
- match: { status: 404 }
- match: { error: 'type [not*] missing' }
- is_true: test_index.mappings.test_type
---
"Existent and non-existent type returns 404 and the existing type":
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
analyzer: whitespace
- do:
catch: missing
indices.get_mapping:
include_type_name: true
index: test_index
type: test_type,not_test_type
- match: { status: 404 }
- match: { error: 'type [not_test_type] missing' }
- is_true: test_index.mappings.test_type
---
"Existent and non-existent types returns 404 and the existing type":
- do:
indices.create:
include_type_name: true
index: test_index
body:
mappings:
test_type:
properties:
text:
type: text
analyzer: whitespace
- do:
catch: missing
indices.get_mapping:
include_type_name: true
index: test_index
type: test_type,not_test_type,another_not_test_type
- match: { status: 404 }
- match: { error: 'types [another_not_test_type,not_test_type] missing' }
- is_true: test_index.mappings.test_type
---
"Type missing when no types exist":
- do:
catch: missing
indices.get_mapping:
include_type_name: true
type: not_test_type

View File

@ -18,7 +18,6 @@
- do: - do:
indices.get_mapping: indices.get_mapping:
include_type_name: false
index: test_alias index: test_alias
- match: {test_index.mappings.properties.text.type: text} - match: {test_index.mappings.properties.text.type: text}

View File

@ -1,20 +0,0 @@
---
setup:
- do:
indices.create:
index: test_1
- do:
indices.create:
index: test_2
---
"Check empty mapping when getting all mappings via /_mapping":
- do:
indices.get_mapping:
include_type_name: true
- match: { test_1.mappings: {}}
- match: { test_2.mappings: {}}

View File

@ -64,6 +64,9 @@
--- ---
"Put mappings with explicit _doc type": "Put mappings with explicit _doc type":
- skip:
version: " - 1.99.99"
reason: "deprecation message changed in 2.0"
- do: - do:
indices.create: indices.create:
index: test_index index: test_index
@ -78,6 +81,31 @@
field: field:
type: keyword type: keyword
- match: { error.type: "illegal_argument_exception" }
- match: { error.reason: "Types cannot be provided in put mapping requests" }
---
"Put mappings with explicit _doc type bwc":
- skip:
version: "2.0.0 - "
reason: "old deprecation message for pre 2.0"
features: "node_selector"
- do:
indices.create:
index: test_index
- do:
node_selector:
version: " - 1.99.99"
catch: bad_request
indices.put_mapping:
index: test_index
body:
_doc:
properties:
field:
type: keyword
- match: { error.type: "illegal_argument_exception" } - match: { error.type: "illegal_argument_exception" }
- match: { error.reason: "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true." } - match: { error.reason: "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true." }

View File

@ -68,15 +68,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
@Override @Override
public List<Route> routes() { public List<Route> routes() {
return unmodifiableList( return unmodifiableList(asList(new Route(GET, "/_mapping/field/{fields}"), new Route(GET, "/{index}/_mapping/field/{fields}")));
asList(
new Route(GET, "/_mapping/field/{fields}"),
new Route(GET, "/_mapping/{type}/field/{fields}"),
new Route(GET, "/{index}/_mapping/field/{fields}"),
new Route(GET, "/{index}/{type}/_mapping/field/{fields}"),
new Route(GET, "/{index}/_mapping/{type}/field/{fields}")
)
);
} }
@Override @Override
@ -87,21 +79,20 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
@Override @Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
final String[] fields = Strings.splitStringByCommaToArray(request.param("fields")); final String[] fields = Strings.splitStringByCommaToArray(request.param("fields"));
boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); GetFieldMappingsRequest getMappingsRequest = new GetFieldMappingsRequest();
if (includeTypeName == false && types.length > 0) { getMappingsRequest.indices(indices).fields(fields).includeDefaults(request.paramAsBoolean("include_defaults", false));
throw new IllegalArgumentException("Types cannot be specified unless include_type_name" + " is set to true."); getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
}
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) { if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
if (includeTypeName) {
throw new IllegalArgumentException(INCLUDE_TYPE_NAME_PARAMETER + " no longer supports the value [true].");
}
deprecationLogger.deprecate("get_field_mapping_with_types", TYPES_DEPRECATION_MESSAGE); deprecationLogger.deprecate("get_field_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
} }
GetFieldMappingsRequest getMappingsRequest = new GetFieldMappingsRequest();
getMappingsRequest.indices(indices).types(types).fields(fields).includeDefaults(request.paramAsBoolean("include_defaults", false));
getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
if (request.hasParam("local")) { if (request.hasParam("local")) {
deprecationLogger.deprecate( deprecationLogger.deprecate(
"get_field_mapping_local", "get_field_mapping_local",
@ -116,7 +107,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBuilder builder) throws Exception { public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBuilder builder) throws Exception {
Map<String, Map<String, Map<String, FieldMappingMetadata>>> mappingsByIndex = response.mappings(); Map<String, Map<String, Map<String, FieldMappingMetadata>>> mappingsByIndex = response.mappings();
boolean isPossibleSingleFieldRequest = indices.length == 1 && types.length == 1 && fields.length == 1; boolean isPossibleSingleFieldRequest = indices.length == 1 && fields.length == 1;
if (isPossibleSingleFieldRequest && isFieldMappingMissingField(mappingsByIndex)) { if (isPossibleSingleFieldRequest && isFieldMappingMissingField(mappingsByIndex)) {
return new BytesRestResponse(OK, builder.startObject().endObject()); return new BytesRestResponse(OK, builder.startObject().endObject());
} }
@ -126,7 +117,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
status = NOT_FOUND; status = NOT_FOUND;
} }
response.toXContent(builder, request); response.toXContent(builder, request);
return new BytesRestResponse(status, builder); return new BytesRestResponse(RestStatus.OK, builder);
} }
}); });
} }

View File

@ -32,7 +32,6 @@
package org.opensearch.rest.action.admin.indices; package org.opensearch.rest.action.admin.indices;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchTimeoutException; import org.opensearch.OpenSearchTimeoutException;
@ -41,15 +40,10 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.opensearch.action.support.IndicesOptions; import org.opensearch.action.support.IndicesOptions;
import org.opensearch.client.node.NodeClient; import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.Strings; import org.opensearch.common.Strings;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.regex.Regex;
import org.opensearch.common.unit.TimeValue; import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.set.Sets;
import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.indices.TypeMissingException;
import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestRequest; import org.opensearch.rest.RestRequest;
@ -60,19 +54,11 @@ import org.opensearch.rest.action.RestBuilderListener;
import org.opensearch.threadpool.ThreadPool; import org.opensearch.threadpool.ThreadPool;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.SortedSet;
import java.util.stream.Collectors;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableList;
import static org.opensearch.rest.RestRequest.Method.GET; import static org.opensearch.rest.RestRequest.Method.GET;
import static org.opensearch.rest.RestRequest.Method.HEAD;
public class RestGetMappingAction extends BaseRestHandler { public class RestGetMappingAction extends BaseRestHandler {
private static final Logger logger = LogManager.getLogger(RestGetMappingAction.class); private static final Logger logger = LogManager.getLogger(RestGetMappingAction.class);
@ -92,13 +78,8 @@ public class RestGetMappingAction extends BaseRestHandler {
asList( asList(
new Route(GET, "/_mapping"), new Route(GET, "/_mapping"),
new Route(GET, "/_mappings"), new Route(GET, "/_mappings"),
new Route(GET, "/{index}/{type}/_mapping"),
new Route(GET, "/{index}/_mapping"), new Route(GET, "/{index}/_mapping"),
new Route(GET, "/{index}/_mappings"), new Route(GET, "/{index}/_mappings")
new Route(GET, "/{index}/_mappings/{type}"),
new Route(GET, "/{index}/_mapping/{type}"),
new Route(HEAD, "/{index}/_mapping/{type}"),
new Route(GET, "/_mapping/{type}")
) )
); );
} }
@ -111,22 +92,9 @@ public class RestGetMappingAction extends BaseRestHandler {
@Override @Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
if (request.method().equals(HEAD)) {
deprecationLogger.deprecate("get_mapping_types_removal", "Type exists requests are deprecated, as types have been deprecated.");
} else if (includeTypeName == false && types.length > 0) {
throw new IllegalArgumentException(
"Types cannot be provided in get mapping requests, unless" + " include_type_name is set to true."
);
}
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
deprecationLogger.deprecate("get_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
}
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); final GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
getMappingsRequest.indices(indices).types(types); getMappingsRequest.indices(indices);
getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions())); getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
final TimeValue timeout = request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout()); final TimeValue timeout = request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout());
getMappingsRequest.masterNodeTimeout(timeout); getMappingsRequest.masterNodeTimeout(timeout);
@ -146,59 +114,10 @@ public class RestGetMappingAction extends BaseRestHandler {
if (threadPool.relativeTimeInMillis() - startTimeMs > timeout.millis()) { if (threadPool.relativeTimeInMillis() - startTimeMs > timeout.millis()) {
throw new OpenSearchTimeoutException("Timed out getting mappings"); throw new OpenSearchTimeoutException("Timed out getting mappings");
} }
final ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappingsByIndex = response
.getMappings();
if (mappingsByIndex.isEmpty() && types.length != 0) {
builder.close();
return new BytesRestResponse(channel, new TypeMissingException("_all", String.join(",", types)));
}
final Set<String> typeNames = new HashSet<>();
for (final ObjectCursor<ImmutableOpenMap<String, MappingMetadata>> cursor : mappingsByIndex.values()) {
for (final ObjectCursor<String> inner : cursor.value.keys()) {
typeNames.add(inner.value);
}
}
final SortedSet<String> difference = Sets.sortedDifference(
Arrays.stream(types).collect(Collectors.toSet()),
typeNames
);
// now remove requested aliases that contain wildcards that are simple matches
final List<String> matches = new ArrayList<>();
outer: for (final String pattern : difference) {
if (pattern.contains("*")) {
for (final String typeName : typeNames) {
if (Regex.simpleMatch(pattern, typeName)) {
matches.add(pattern);
continue outer;
}
}
}
}
difference.removeAll(matches);
final RestStatus status;
builder.startObject(); builder.startObject();
{
if (difference.isEmpty()) {
status = RestStatus.OK;
} else {
status = RestStatus.NOT_FOUND;
final String message = String.format(
Locale.ROOT,
"type" + (difference.size() == 1 ? "" : "s") + " [%s] missing",
Strings.collectionToCommaDelimitedString(difference)
);
builder.field("error", message);
builder.field("status", status.getStatus());
}
response.toXContent(builder, request); response.toXContent(builder, request);
}
builder.endObject(); builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
return new BytesRestResponse(status, builder);
} }
}.onResponse(getMappingsResponse))); }.onResponse(getMappingsResponse)));
} }

View File

@ -50,7 +50,6 @@ import java.util.Map;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableList;
import static org.opensearch.client.Requests.putMappingRequest; import static org.opensearch.client.Requests.putMappingRequest;
import static org.opensearch.index.mapper.MapperService.isMappingSourceTyped;
import static org.opensearch.rest.RestRequest.Method.POST; import static org.opensearch.rest.RestRequest.Method.POST;
import static org.opensearch.rest.RestRequest.Method.PUT; import static org.opensearch.rest.RestRequest.Method.PUT;
@ -65,20 +64,8 @@ public class RestPutMappingAction extends BaseRestHandler {
asList( asList(
new Route(POST, "/{index}/_mapping/"), new Route(POST, "/{index}/_mapping/"),
new Route(PUT, "/{index}/_mapping/"), new Route(PUT, "/{index}/_mapping/"),
new Route(POST, "/{index}/{type}/_mapping"),
new Route(PUT, "/{index}/{type}/_mapping"),
new Route(POST, "/{index}/_mapping/{type}"),
new Route(PUT, "/{index}/_mapping/{type}"),
new Route(POST, "/_mapping/{type}"),
new Route(PUT, "/_mapping/{type}"),
new Route(POST, "/{index}/_mappings/"), new Route(POST, "/{index}/_mappings/"),
new Route(PUT, "/{index}/_mappings/"), new Route(PUT, "/{index}/_mappings/")
new Route(POST, "/{index}/{type}/_mappings"),
new Route(PUT, "/{index}/{type}/_mappings"),
new Route(POST, "/{index}/_mappings/{type}"),
new Route(PUT, "/{index}/_mappings/{type}"),
new Route(POST, "/_mappings/{type}"),
new Route(PUT, "/_mappings/{type}")
) )
); );
} }
@ -90,21 +77,20 @@ public class RestPutMappingAction extends BaseRestHandler {
@Override @Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY);
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) { if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
deprecationLogger.deprecate("put_mapping_with_types", TYPES_DEPRECATION_MESSAGE); deprecationLogger.deprecate("put_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
} }
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); putMappingRequest.type(MapperService.SINGLE_MAPPING_NAME);
final String type = request.param("type");
putMappingRequest.type(includeTypeName ? type : MapperService.SINGLE_MAPPING_NAME);
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2(); Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2();
if (includeTypeName == false && (type != null || isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap))) {
throw new IllegalArgumentException( if (includeTypeName == false && MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap)) {
"Types cannot be provided in put mapping requests, unless " + "the include_type_name parameter is set to true." throw new IllegalArgumentException("Types cannot be provided in put mapping requests");
);
} }
putMappingRequest.source(sourceAsMap); putMappingRequest.source(sourceAsMap);