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] Type from PutIndexTemplateRequest and PITRB #2497

Merged
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 @@ -62,7 +62,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
PutMappingRequest.simpleMapping(
"my_feature_field",
"type=rank_feature",
"my_negative_feature_field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public void testPercolatorQueryWithHighlighting() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "id", "type=keyword", "field1", fieldMapping, "query", "type=percolator")
.addMapping("type", "id", "type=keyword", "field1", fieldMapping.toString(), "query", "type=percolator")
);
client().prepareIndex("test")
.setId("1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
docType,
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField)
PutMappingRequest.simpleMapping(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField)
)
),
MapperService.MergeReason.MAPPING_UPDATE
);
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(TEXT_FIELD_NAME, "type=text"))),
new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping(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("some_nested_object", "type=nested"))),
new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping("some_nested_object", "type=nested"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void createIndex() {
logger.info("--> creating index test");
client().admin()
.indices()
.create(createIndexRequest("test1").mapping("type1", "name", "type=keyword,store=true").alias(new Alias("test")))
.create(createIndexRequest("test1").simpleMapping("name", "type=keyword,store=true").alias(new Alias("test")))
.actionGet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,31 @@ public void testGlobalTemplatesDoNotApply() {
.indices()
.preparePutTemplate("a_global_template")
.setPatterns(Collections.singletonList("*"))
.addMapping("_doc", "foo", "type=text")
.setMapping("foo", "type=text")
.get()
);
assertAcked(
client().admin()
.indices()
.preparePutTemplate("not_global_template")
.setPatterns(Collections.singletonList("a*"))
.addMapping("_doc", "bar", "type=text")
.setMapping("bar", "type=text")
.get()
);
assertAcked(
client().admin()
.indices()
.preparePutTemplate("specific_template")
.setPatterns(Collections.singletonList("a_hidden_index"))
.addMapping("_doc", "baz", "type=text")
.setMapping("baz", "type=text")
.get()
);
assertAcked(
client().admin()
.indices()
.preparePutTemplate("unused_template")
.setPatterns(Collections.singletonList("not_used"))
.addMapping("_doc", "foobar", "type=text")
.setMapping("foobar", "type=text")
.get()
);

Expand Down Expand Up @@ -192,7 +192,7 @@ public void testNonGlobalTemplateCanMakeIndexHidden() {
.indices()
.preparePutTemplate("a_global_template")
.setPatterns(Collections.singletonList("my_hidden_pattern*"))
.addMapping("_doc", "foo", "type=text")
.setMapping("foo", "type=text")
.setSettings(Settings.builder().put("index.hidden", true).build())
.get()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public void testIndexTemplateWithAliases() throws Exception {
.indices()
.preparePutTemplate("template_with_aliases")
.setPatterns(Collections.singletonList("te*"))
.addMapping("_doc", "type", "type=keyword", "field", "type=text")
.setMapping("type", "type=keyword", "field", "type=text")
.addAlias(new Alias("simple_alias"))
.addAlias(new Alias("templated_alias-{index}"))
.addAlias(new Alias("filtered_alias").filter("{\"term\":{\"type\":\"type2\"}}"))
Expand Down Expand Up @@ -820,7 +820,7 @@ public void testStrictAliasParsingInIndicesCreatedViaTemplates() throws Exceptio
.preparePutTemplate("template1")
.setPatterns(Collections.singletonList("a*"))
.setOrder(0)
.addMapping("test", "field", "type=text")
.setMapping("field", "type=text")
.addAlias(new Alias("alias1").filter(termQuery("field", "value")))
.get();
// Indexing into b index should fail, since there is field with name 'field' in the mapping
Expand Down Expand Up @@ -930,7 +930,7 @@ public void testOrderAndVersion() {
.setPatterns(Collections.singletonList("te*"))
.setVersion(version)
.setOrder(order)
.addMapping("test", "field", "type=text")
.setMapping("field", "type=text")
.get()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private Set<String> prepareData(int numShards) throws Exception {

client().admin()
.indices()
.create(createIndexRequest("test").settings(settingsBuilder).mapping("type", "foo", "type=geo_point"))
.create(createIndexRequest("test").settings(settingsBuilder).simpleMapping("foo", "type=geo_point"))
.actionGet();

ensureGreen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private void createIndexMappingsFromObjectType(String indexName, String typeName
fail("Can't match type [" + type + "]");
}
}
indexRequestBuilder.addMapping(typeName, mappings.toArray()).get();
indexRequestBuilder.addMapping(typeName, mappings.toArray(new String[0])).get();
ensureGreen();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,9 @@ private CreateIndexRequest mapping(String type, Map<String, ?> source) {
/**
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
* @deprecated types are being removed
*/
@Deprecated
public CreateIndexRequest mapping(String type, Object... source) {
mapping(PutMappingRequest.buildFromSimplifiedDef(source));
public CreateIndexRequest simpleMapping(String... source) {
mapping(PutMappingRequest.simpleMapping(source));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public CreateIndexRequestBuilder setMapping(Map<String, Object> source) {
* @deprecated types are being removed
*/
@Deprecated
public CreateIndexRequestBuilder addMapping(String type, Object... source) {
request.mapping(type, source);
public CreateIndexRequestBuilder addMapping(String type, String... source) {
request.simpleMapping(source);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ public String source() {
* Also supports metadata mapping fields such as `_all` and `_parent` as property definition, these metadata
* mapping fields will automatically be put on the top level mapping object.
*/
public PutMappingRequest source(Object... source) {
return source(buildFromSimplifiedDef(source));
public PutMappingRequest source(String... source) {
return source(simpleMapping(source));
}

public String origin() {
Expand All @@ -239,7 +239,7 @@ public PutMappingRequest origin(String origin) {
* if the number of the source arguments is not divisible by two
* @return the mappings definition
*/
public static XContentBuilder buildFromSimplifiedDef(Object... source) {
public static XContentBuilder simpleMapping(String... source) {
if (source.length % 2 != 0) {
throw new IllegalArgumentException("mapping source must be pairs of fieldnames and properties definition.");
}
Expand All @@ -248,10 +248,10 @@ public static XContentBuilder buildFromSimplifiedDef(Object... source) {
builder.startObject();

for (int i = 0; i < source.length; i++) {
String fieldName = source[i++].toString();
String fieldName = source[i++];
if (RESERVED_FIELDS.contains(fieldName)) {
builder.startObject(fieldName);
String[] s1 = Strings.splitStringByCommaToArray(source[i].toString());
String[] s1 = Strings.splitStringByCommaToArray(source[i]);
for (String s : s1) {
String[] s2 = Strings.split(s, "=");
if (s2.length != 2) {
Expand All @@ -265,13 +265,13 @@ public static XContentBuilder buildFromSimplifiedDef(Object... source) {

builder.startObject("properties");
for (int i = 0; i < source.length; i++) {
String fieldName = source[i++].toString();
String fieldName = source[i++];
if (RESERVED_FIELDS.contains(fieldName)) {
continue;
}

builder.startObject(fieldName);
String[] s1 = Strings.splitStringByCommaToArray(source[i].toString());
String[] s1 = Strings.splitStringByCommaToArray(source[i]);
for (String s : s1) {
String[] s2 = Strings.split(s, "=");
if (s2.length != 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public PutMappingRequestBuilder setSource(String mappingSource, XContentType xCo
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
*/
public PutMappingRequestBuilder setSource(Object... source) {
public PutMappingRequestBuilder setSource(String... source) {
request.source(source);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public RolloverRequestBuilder alias(Alias alias) {
return this;
}

public RolloverRequestBuilder mapping(String type, Object... source) {
this.request.getCreateIndexRequest().mapping(type, source);
public RolloverRequestBuilder simpleMapping(String... source) {
this.request.getCreateIndexRequest().simpleMapping(source);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.mapper.MapperService;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -303,8 +304,8 @@ public PutIndexTemplateRequest mapping(String type, Map<String, Object> source)
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
*/
public PutIndexTemplateRequest mapping(String type, Object... source) {
mapping(type, PutMappingRequest.buildFromSimplifiedDef(source));
public PutIndexTemplateRequest mapping(String... source) {
mapping(MapperService.SINGLE_MAPPING_NAME, PutMappingRequest.simpleMapping(source));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public PutIndexTemplateRequestBuilder addMapping(String type, String source, XCo
* A specialized simplified mapping source method, takes the form of simple properties definition:
* ("field1", "type=string,store=true").
*/
public PutIndexTemplateRequestBuilder addMapping(String type, Object... source) {
request.mapping(type, source);
public PutIndexTemplateRequestBuilder setMapping(String... source) {
request.mapping(source);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ public void testValidation() {
}

/**
* Test that {@link PutMappingRequest#buildFromSimplifiedDef(Object...)}
* Test that {@link PutMappingRequest#simpleMapping(String...)}
* rejects inputs where the {@code Object...} varargs of field name and properties are not
* paired correctly
*/
public void testBuildFromSimplifiedDef() {
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> PutMappingRequest.buildFromSimplifiedDef("only_field")
);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> PutMappingRequest.simpleMapping("only_field"));
assertEquals("mapping source must be pairs of fieldnames and properties definition.", e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
PutMappingRequest.simpleMapping(
INTEGER_RANGE_FIELD_NAME,
"type=integer_range",
LONG_RANGE_FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef("string_boost", "type=text", "string_no_pos", "type=text,index_options=docs")
PutMappingRequest.simpleMapping("string_boost", "type=text", "string_no_pos", "type=text,index_options=docs")
)
),
MapperService.MergeReason.MAPPING_UPDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
PutMappingRequest.simpleMapping(
TEXT_FIELD_NAME,
"type=text",
INT_FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ public void testDisabledFieldNamesField() throws Exception {
.merge(
"_doc",
new CompressedXContent(
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=false"))
Strings.toString(PutMappingRequest.simpleMapping("foo", "type=text", "_field_names", "enabled=false"))
),
MapperService.MergeReason.MAPPING_UPDATE
);
Expand All @@ -1112,7 +1112,7 @@ public void testDisabledFieldNamesField() throws Exception {
.merge(
"_doc",
new CompressedXContent(
Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=true"))
Strings.toString(PutMappingRequest.simpleMapping("foo", "type=text", "_field_names", "enabled=true"))
),
MapperService.MergeReason.MAPPING_UPDATE
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
String docType = "_doc";
mapperService.merge(
docType,
new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("m_s_m", "type=long"))),
new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping("m_s_m", "type=long"))),
MapperService.MergeReason.MAPPING_UPDATE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void onRemoval(ShardId shardId, Accountable accountable) {
"_doc",
new CompressedXContent(
Strings.toString(
PutMappingRequest.buildFromSimplifiedDef(
PutMappingRequest.simpleMapping(
TEXT_FIELD_NAME,
"type=text",
KEYWORD_FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ protected IndexService createIndex(String index, Settings settings, String type,
* @deprecated types are being removed
*/
@Deprecated
protected IndexService createIndex(String index, Settings settings, String type, Object... mappings) {
protected IndexService createIndex(String index, Settings settings, String type, String... mappings) {
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
if (type != null) {
createIndexRequestBuilder.addMapping(type, mappings);
Expand Down