[Remove] Types from PutIndexTemplateRequest and builder to reduce mapping to a string (#2510)

Signed-off-by: Suraj Singh <surajrider@gmail.com>
This commit is contained in:
Suraj Singh 2022-03-21 16:49:18 -07:00 committed by GitHub
parent 4bb8add982
commit 59d1e69129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 85 additions and 160 deletions

View File

@ -166,11 +166,9 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("foo_template")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -182,7 +180,6 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();
@ -191,11 +188,9 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("fuu_template")
.setPatterns(Collections.singletonList("test*"))
.setOrder(1)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field2")
.field("type", "text")
@ -203,7 +198,6 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();

View File

@ -461,11 +461,9 @@ public class RecoveryFromGatewayIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -477,7 +475,6 @@ public class RecoveryFromGatewayIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();

View File

@ -54,11 +54,9 @@ public class IndexTemplateBlocksIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_blocks")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -70,7 +68,6 @@ public class IndexTemplateBlocksIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();

View File

@ -110,11 +110,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.setPatterns(Collections.singletonList("te*"))
.setSettings(indexSettings())
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -126,7 +124,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();
@ -136,11 +133,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.setPatterns(Collections.singletonList("test*"))
.setSettings(indexSettings())
.setOrder(1)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field2")
.field("type", "text")
@ -148,7 +143,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();
@ -161,11 +155,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.setSettings(indexSettings())
.setCreate(true)
.setOrder(1)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field2")
.field("type", "text")
@ -173,7 +165,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
),
IllegalArgumentException.class
);
@ -223,11 +214,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -239,7 +228,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -249,11 +237,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("test*"))
.setOrder(1)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field2")
.field("type", "text")
@ -261,7 +247,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -281,11 +266,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -297,7 +280,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -322,11 +304,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.setVersion(123)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -338,7 +318,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -367,11 +346,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -383,7 +360,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -394,11 +370,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -410,7 +384,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -421,11 +394,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template3")
.setPatterns(Collections.singletonList("te*"))
.setOrder(0)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -437,7 +408,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.execute()
.actionGet();
@ -507,7 +477,7 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.indices()
.preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.addMapping("type1", "{\"foo\": \"abcde\"}", XContentType.JSON)
.setMapping("{\"foo\": \"abcde\"}", XContentType.JSON)
.get()
);
assertThat(e.getMessage(), containsString("Failed to parse mapping "));
@ -896,11 +866,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.setPatterns(Collections.singletonList("test*"))
.setCreate(true)
.setOrder(1)
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field2")
.field("type", "text")
@ -908,7 +876,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get()
);
@ -946,11 +913,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.preparePutTemplate("template_1")
.setPatterns(Arrays.asList("a*", "b*"))
.setSettings(indexSettings())
.addMapping(
"type1",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -962,7 +927,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get();
@ -1027,7 +991,7 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase {
.indices()
.preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("te*"))
.addMapping("type", "{\"type\":{\"_routing\":{\"required\":false}}}", XContentType.JSON)
.setMapping("{\"_routing\":{\"required\":false}}", XContentType.JSON)
.setSettings(Settings.builder().put("index.number_of_shards", "6").put("index.routing_partition_size", "3"))
.get()
);

View File

@ -424,11 +424,9 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase {
.indices()
.preparePutTemplate("test-template")
.setPatterns(Collections.singletonList("te*"))
.addMapping(
"_doc",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -440,7 +438,6 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get()
.isAcknowledged(),

View File

@ -81,11 +81,9 @@ public class SnapshotCustomPluginStateIT extends AbstractSnapshotIntegTestCase {
.indices()
.preparePutTemplate("test-template")
.setPatterns(Collections.singletonList("te*"))
.addMapping(
"_doc",
.setMapping(
XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -97,7 +95,6 @@ public class SnapshotCustomPluginStateIT extends AbstractSnapshotIntegTestCase {
.endObject()
.endObject()
.endObject()
.endObject()
)
.get()
.isAcknowledged(),

View File

@ -33,16 +33,17 @@ package org.opensearch.action.admin.indices.template.put;
import org.opensearch.OpenSearchGenerationException;
import org.opensearch.OpenSearchParseException;
import org.opensearch.Version;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.IndicesRequest;
import org.opensearch.action.admin.indices.alias.Alias;
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.opensearch.action.support.IndicesOptions;
import org.opensearch.action.support.master.MasterNodeRequest;
import org.opensearch.common.Nullable;
import org.opensearch.common.Strings;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.collect.MapBuilder;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.logging.DeprecationLogger;
@ -62,7 +63,6 @@ import org.opensearch.index.mapper.MapperService;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -94,7 +94,8 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
private Settings settings = EMPTY_SETTINGS;
private Map<String, String> mappings = new HashMap<>();
@Nullable
private String mappings;
private final Set<Alias> aliases = new HashSet<>();
@ -108,11 +109,14 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
order = in.readInt();
create = in.readBoolean();
settings = readSettingsFromStream(in);
if (in.getVersion().before(Version.V_2_0_0)) {
int size = in.readVInt();
for (int i = 0; i < size; i++) {
final String type = in.readString();
String mappingSource = in.readString();
mappings.put(type, mappingSource);
in.readString(); // type - cannot assert on _doc because 7x allows arbitrary type names
this.mappings = in.readString();
}
} else {
this.mappings = in.readOptionalString();
}
int aliasesSize = in.readVInt();
for (int i = 0; i < aliasesSize; i++) {
@ -233,17 +237,6 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
return this.settings;
}
/**
* Adds mapping that will be added when the index gets created.
*
* @param type The mapping type
* @param source The mapping source
* @param xContentType The type of content contained within the source
*/
public PutIndexTemplateRequest mapping(String type, String source, XContentType xContentType) {
return mapping(type, new BytesArray(source), xContentType);
}
/**
* The cause for this index template creation.
*/
@ -259,41 +252,47 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
/**
* Adds mapping that will be added when the index gets created.
*
* @param type The mapping type
* @param source The mapping source
* @param xContentType The type of content contained within the source
*/
public PutIndexTemplateRequest mapping(String type, XContentBuilder source) {
return mapping(type, BytesReference.bytes(source), source.contentType());
public PutIndexTemplateRequest mapping(String source, XContentType xContentType) {
return mapping(new BytesArray(source), xContentType);
}
/**
* Adds mapping that will be added when the index gets created.
*
* @param source The mapping source
*/
public PutIndexTemplateRequest mapping(XContentBuilder source) {
return mapping(BytesReference.bytes(source), source.contentType());
}
/**
* Adds mapping that will be added when the index gets created.
*
* @param type The mapping type
* @param source The mapping source
* @param xContentType the source content type
*/
public PutIndexTemplateRequest mapping(String type, BytesReference source, XContentType xContentType) {
public PutIndexTemplateRequest mapping(BytesReference source, XContentType xContentType) {
Objects.requireNonNull(xContentType);
Map<String, Object> mappingAsMap = XContentHelper.convertToMap(source, false, xContentType).v2();
return mapping(type, mappingAsMap);
return mapping(mappingAsMap);
}
/**
* Adds mapping that will be added when the index gets created.
*
* @param type The mapping type
* @param source The mapping source
*/
public PutIndexTemplateRequest mapping(String type, Map<String, Object> source) {
// wrap it in a type map if its not
if (source.size() != 1 || !source.containsKey(type)) {
source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map();
public PutIndexTemplateRequest mapping(Map<String, Object> source) {
if (source.size() != 1 || source.containsKey(MapperService.SINGLE_MAPPING_NAME) == false) {
source = Map.of(MapperService.SINGLE_MAPPING_NAME, source);
}
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.map(source);
mappings.put(type, Strings.toString(builder));
mappings = Strings.toString(builder);
return this;
} catch (IOException e) {
throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e);
@ -305,11 +304,11 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
* ("field1", "type=string,store=true").
*/
public PutIndexTemplateRequest mapping(String... source) {
mapping(MapperService.SINGLE_MAPPING_NAME, PutMappingRequest.simpleMapping(source));
mapping(PutMappingRequest.simpleMapping(source));
return this;
}
public Map<String, String> mappings() {
public String mappings() {
return this.mappings;
}
@ -372,7 +371,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
+ "], should include an inner object describing the mapping"
);
}
mapping(entry1.getKey(), (Map<String, Object>) entry1.getValue());
mapping((Map<String, Object>) entry1.getValue());
}
} else if (name.equals("aliases")) {
aliases((Map<String, Object>) entry.getValue());
@ -489,10 +488,14 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
out.writeInt(order);
out.writeBoolean(create);
writeSettingsToStream(settings, out);
out.writeVInt(mappings.size());
for (Map.Entry<String, String> entry : mappings.entrySet()) {
out.writeString(entry.getKey());
out.writeString(entry.getValue());
if (out.getVersion().before(Version.V_2_0_0)) {
out.writeVInt(mappings == null ? 0 : 1);
if (mappings != null) {
out.writeString(MapperService.SINGLE_MAPPING_NAME);
out.writeString(mappings);
}
} else {
out.writeOptionalString(mappings);
}
out.writeVInt(aliases.size());
for (Alias alias : aliases) {
@ -516,20 +519,19 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
builder.endObject();
builder.startObject("mappings");
for (Map.Entry<String, String> entry : mappings.entrySet()) {
builder.field(entry.getKey());
if (mappings != null) {
builder.field(MapperService.SINGLE_MAPPING_NAME);
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
entry.getValue()
mappings
)
) {
builder.copyCurrentStructure(parser);
}
}
builder.endObject();
builder.startObject("aliases");
for (Alias alias : aliases) {
alias.toXContent(builder, params);

View File

@ -124,12 +124,11 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu
/**
* Adds mapping that will be added when the index template gets created.
*
* @param type The mapping type
* @param source The mapping source
* @param xContentType The type/format of the source
*/
public PutIndexTemplateRequestBuilder addMapping(String type, String source, XContentType xContentType) {
request.mapping(type, source, xContentType);
public PutIndexTemplateRequestBuilder setMapping(String source, XContentType xContentType) {
request.mapping(source, xContentType);
return this;
}
@ -196,22 +195,10 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu
/**
* Adds mapping that will be added when the index template gets created.
*
* @param type The mapping type
* @param source The mapping source
*/
public PutIndexTemplateRequestBuilder addMapping(String type, XContentBuilder source) {
request.mapping(type, source);
return this;
}
/**
* Adds mapping that will be added when the index gets created.
*
* @param type The mapping type
* @param source The mapping source
*/
public PutIndexTemplateRequestBuilder addMapping(String type, Map<String, Object> source) {
request.mapping(type, source);
public PutIndexTemplateRequestBuilder setMapping(XContentBuilder source) {
request.mapping(source);
return this;
}

View File

@ -915,11 +915,11 @@ public class MetadataIndexTemplateService {
templateBuilder.patterns(request.indexPatterns);
templateBuilder.settings(request.settings);
for (Map.Entry<String, String> entry : request.mappings.entrySet()) {
if (request.mappings != null) {
try {
templateBuilder.putMapping(entry.getKey(), entry.getValue());
templateBuilder.putMapping(MapperService.SINGLE_MAPPING_NAME, request.mappings);
} catch (Exception e) {
throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage());
throw new MapperParsingException("Failed to parse mapping: {}", e, request.mappings);
}
}
@ -1511,7 +1511,7 @@ public class MetadataIndexTemplateService {
Integer version;
List<String> indexPatterns;
Settings settings = Settings.Builder.EMPTY_SETTINGS;
Map<String, String> mappings = new HashMap<>();
String mappings = null;
List<Alias> aliases = new ArrayList<>();
TimeValue masterTimeout = MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT;
@ -1541,8 +1541,8 @@ public class MetadataIndexTemplateService {
return this;
}
public PutRequest mappings(Map<String, String> mappings) {
this.mappings.putAll(mappings);
public PutRequest mappings(String mappings) {
this.mappings = mappings;
return this;
}
@ -1551,11 +1551,6 @@ public class MetadataIndexTemplateService {
return this;
}
public PutRequest putMapping(String mappingType, String mappingSource) {
mappings.put(mappingType, mappingSource);
return this;
}
public PutRequest masterTimeout(TimeValue masterTimeout) {
this.masterTimeout = masterTimeout;
return this;

View File

@ -39,6 +39,7 @@ import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.test.AbstractXContentTestCase;
import java.io.IOException;
@ -90,10 +91,9 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIn
.endObject()
.endObject()
.endObject();
request1.mapping("type1", builder);
request1.mapping(builder);
builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
builder.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
@ -106,17 +106,16 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIn
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
request2.mapping("type1", builder);
request2.mapping(builder);
assertEquals(request1.mappings(), request2.mappings());
}
{
request1 = new PutIndexTemplateRequest("foo");
request2 = new PutIndexTemplateRequest("bar");
String nakedMapping = "{\"properties\": {\"foo\": {\"type\": \"integer\"}}}";
request1.mapping("type2", nakedMapping, XContentType.JSON);
request2.mapping("type2", "{\"type2\": " + nakedMapping + "}", XContentType.JSON);
request1.mapping(nakedMapping, XContentType.JSON);
request2.mapping(nakedMapping, XContentType.JSON);
assertEquals(request1.mappings(), request2.mappings());
}
{
@ -130,8 +129,8 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIn
.map()
)
.map();
request1.mapping("type3", nakedMapping);
request2.mapping("type3", MapBuilder.<String, Object>newMapBuilder().put("type3", nakedMapping).map());
request1.mapping(nakedMapping);
request2.mapping(MapBuilder.<String, Object>newMapBuilder().put(MapperService.SINGLE_MAPPING_NAME, nakedMapping).map());
assertEquals(request1.mappings(), request2.mappings());
}
}
@ -163,7 +162,6 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIn
if (randomBoolean()) {
try {
request.mapping(
"doc",
XContentFactory.jsonBuilder()
.startObject()
.startObject("doc")

View File

@ -185,12 +185,10 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC
public void testIndexTemplateWithValidateMapping() throws Exception {
PutRequest request = new PutRequest("api", "validate_template");
request.patterns(singletonList("te*"));
request.putMapping(
"type1",
request.mappings(
Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field2")
.field("type", "text")
@ -198,7 +196,6 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC
.endObject()
.endObject()
.endObject()
.endObject()
)
);
@ -211,7 +208,7 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC
public void testBrokenMapping() throws Exception {
PutRequest request = new PutRequest("api", "broken_mapping");
request.patterns(singletonList("te*"));
request.putMapping("type1", "abcde");
request.mappings("abcde");
List<Throwable> errors = putTemplateDetail(request);
assertThat(errors.size(), equalTo(1));
@ -223,7 +220,7 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC
// invalid json: put index template fails
PutRequest request = new PutRequest("api", "blank_mapping");
request.patterns(singletonList("te*"));
request.putMapping("type1", "{}");
request.mappings("{}");
Set<Alias> aliases = new HashSet<>();
aliases.add(new Alias("invalid_alias").filter("abcde"));
request.aliases(aliases);
@ -2073,7 +2070,7 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC
pr.settings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build());
}
if (randomBoolean()) {
pr.mappings(Collections.emptyMap());
pr.mappings("{}");
}
if (randomBoolean()) {
pr.aliases(Collections.singleton(new Alias("alias")));