Skip to content

Commit

Permalink
Merge branch 'main' into cluster-manager-cluster-health
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <[email protected]>
  • Loading branch information
Tianli Feng committed Mar 17, 2022
2 parents 55a62d4 + 2e3d3fe commit 28c671a
Show file tree
Hide file tree
Showing 29 changed files with 49 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testConvertScalarToList() throws Exception {
public void testAppendMetadataExceptVersion() throws Exception {
// here any metadata field value becomes a list, which won't make sense in most of the cases,
// but support for append is streamlined like for set so we test it
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING);
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.ID, Metadata.ROUTING);
List<String> values = new ArrayList<>();
Processor appendProcessor;
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testSetExistingNullFieldWithOverrideDisabled() throws Exception {
}

public void testSetMetadataExceptVersion() throws Exception {
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING);
Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.ID, Metadata.ROUTING);
Processor processor = createSetProcessor(randomMetadata.getFieldName(), "_value", true, false);
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
processor.execute(ingestDocument);
Expand Down
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 @@ -194,12 +194,6 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
Map<String, Object> dataMap = (Map<String, Object>) object;
Map<String, Object> document = ConfigurationUtils.readMap(null, null, dataMap, Fields.SOURCE);
String index = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.INDEX.getFieldName(), "_index");
if (dataMap.containsKey(Metadata.TYPE.getFieldName())) {
deprecationLogger.deprecate(
"simulate_pipeline_with_types",
"[types removal] specifying _type in pipeline simulation requests is deprecated"
);
}
String id = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.ID.getFieldName(), "_id");
String routing = ConfigurationUtils.readOptionalStringOrIntProperty(null, null, dataMap, Metadata.ROUTING.getFieldName());
Long version = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.index.mapper.IndexFieldMapper;
import org.opensearch.index.mapper.RoutingFieldMapper;
import org.opensearch.index.mapper.SourceFieldMapper;
import org.opensearch.index.mapper.TypeFieldMapper;
import org.opensearch.index.mapper.VersionFieldMapper;
import org.opensearch.script.TemplateScript;

Expand Down Expand Up @@ -846,7 +845,6 @@ public String toString() {

public enum Metadata {
INDEX(IndexFieldMapper.NAME),
TYPE(TypeFieldMapper.NAME),
ID(IdFieldMapper.NAME),
ROUTING(RoutingFieldMapper.NAME),
VERSION(VersionFieldMapper.NAME),
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 @@ -57,7 +57,6 @@
import static org.opensearch.ingest.IngestDocument.Metadata.ID;
import static org.opensearch.ingest.IngestDocument.Metadata.INDEX;
import static org.opensearch.ingest.IngestDocument.Metadata.ROUTING;
import static org.opensearch.ingest.IngestDocument.Metadata.TYPE;
import static org.opensearch.ingest.IngestDocument.Metadata.VERSION;
import static org.opensearch.ingest.IngestDocument.Metadata.VERSION_TYPE;
import static org.opensearch.ingest.IngestDocument.Metadata.IF_SEQ_NO;
Expand Down Expand Up @@ -132,15 +131,7 @@ public void testParseUsingPipelineStore(boolean useExplicitType) throws Exceptio
assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(1));
}

public void testParseWithProvidedPipelineNoType() throws Exception {
innerTestParseWithProvidedPipeline(false);
}

public void testParseWithProvidedPipelineWithType() throws Exception {
innerTestParseWithProvidedPipeline(true);
}

private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws Exception {
public void innerTestParseWithProvidedPipeline() throws Exception {
int numDocs = randomIntBetween(1, 10);

Map<String, Object> requestContent = new HashMap<>();
Expand All @@ -150,16 +141,7 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws
for (int i = 0; i < numDocs; i++) {
Map<String, Object> doc = new HashMap<>();
Map<String, Object> expectedDoc = new HashMap<>();
List<IngestDocument.Metadata> fields = Arrays.asList(
INDEX,
TYPE,
ID,
ROUTING,
VERSION,
VERSION_TYPE,
IF_SEQ_NO,
IF_PRIMARY_TERM
);
List<IngestDocument.Metadata> fields = Arrays.asList(INDEX, ID, ROUTING, VERSION, VERSION_TYPE, IF_SEQ_NO, IF_PRIMARY_TERM);
for (IngestDocument.Metadata field : fields) {
if (field == VERSION) {
Long value = randomLong();
Expand All @@ -173,14 +155,6 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws
Long value = randomNonNegativeLong();
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else if (field == TYPE) {
if (useExplicitType) {
String value = randomAlphaOfLengthBetween(1, 10);
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else {
expectedDoc.put(field.getFieldName(), "_doc");
}
} else {
if (randomBoolean()) {
String value = randomAlphaOfLengthBetween(1, 10);
Expand Down Expand Up @@ -249,9 +223,6 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws
assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID));
assertThat(actualRequest.getPipeline().getDescription(), nullValue());
assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(numProcessors));
if (useExplicitType) {
assertWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated");
}
}

public void testNullPipelineId() {
Expand Down
Loading

0 comments on commit 28c671a

Please sign in to comment.