Skip to content

Commit

Permalink
[Remove] types based addMapping method from CreateIndexRequest and Bu…
Browse files Browse the repository at this point in the history
…ilder (#2460)

Removes the obsolete types based .addMapping method from CreateIndexRequest and
CreateIndexRequestBuilder. Tests are refactored to use the new source only
setMapping method.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Mar 15, 2022
1 parent 7df40ee commit b619a05
Show file tree
Hide file tree
Showing 32 changed files with 93 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import org.opensearch.common.Priority;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.monitor.os.OsStats;
import org.opensearch.node.NodeRoleSettings;
import org.opensearch.test.OpenSearchIntegTestCase;
Expand Down Expand Up @@ -276,19 +274,13 @@ public void testFieldTypes() {
assertThat(response.getStatus(), Matchers.equalTo(ClusterHealthStatus.GREEN));
assertTrue(response.getIndicesStats().getMappings().getFieldTypeStats().isEmpty());

client().admin()
.indices()
.prepareCreate("test1")
.addMapping(MapperService.SINGLE_MAPPING_NAME, "{\"properties\":{\"foo\":{\"type\": \"keyword\"}}}", XContentType.JSON)
.get();
client().admin().indices().prepareCreate("test1").setMapping("{\"properties\":{\"foo\":{\"type\": \"keyword\"}}}").get();
client().admin()
.indices()
.prepareCreate("test2")
.addMapping(
MapperService.SINGLE_MAPPING_NAME,
.setMapping(
"{\"properties\":{\"foo\":{\"type\": \"keyword\"},\"bar\":{\"properties\":{\"baz\":{\"type\":\"keyword\"},"
+ "\"eggplant\":{\"type\":\"integer\"}}}}}",
XContentType.JSON
+ "\"eggplant\":{\"type\":\"integer\"}}}}}"
)
.get();
response = client().admin().cluster().prepareClusterStats().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.opensearch.cluster.metadata.MappingMetadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand All @@ -64,12 +63,7 @@
public class GetIndexIT extends OpenSearchIntegTestCase {
@Override
protected void setupSuiteScopeCluster() throws Exception {
assertAcked(
prepareCreate("idx").addAlias(new Alias("alias_idx"))
.addMapping("type1", "{\"type1\":{}}", XContentType.JSON)
.setSettings(Settings.builder().put("number_of_shards", 1))
.get()
);
assertAcked(prepareCreate("idx").addAlias(new Alias("alias_idx")).setSettings(Settings.builder().put("number_of_shards", 1)).get());
ensureSearchable("idx");
createIndex("empty_idx");
ensureSearchable("idx", "empty_idx");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.discovery.MasterNotDiscoveredException;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.test.OpenSearchIntegTestCase;
Expand Down Expand Up @@ -321,11 +320,9 @@ public void testAliasFilterValidation() {
internalCluster().startDataOnlyNode();

assertAcked(
prepareCreate("test").addMapping(
"type1",
"{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", "
+ "\"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}}",
XContentType.JSON
prepareCreate("test").setMapping(
"{\"properties\" : {\"table_a\" : { \"type\" : \"nested\", "
+ "\"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}"
)
);
client().admin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.opensearch.common.Priority;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.index.mapper.MapperParsingException;
import org.opensearch.indices.IndexClosedException;
Expand Down Expand Up @@ -483,19 +482,15 @@ public void testRecoverMissingAnalyzer() throws Exception {
prepareCreate("test").setSettings(
Settings.builder().put("index.analysis.analyzer.test.tokenizer", "standard").put("index.number_of_shards", "1")
)
.addMapping(
"type1",
.setMapping(
"{\n"
+ " \"type1\": {\n"
+ " \"properties\": {\n"
+ " \"field1\": {\n"
+ " \"type\": \"text\",\n"
+ " \"analyzer\": \"test\"\n"
+ " }\n"
+ " \"properties\": {\n"
+ " \"field1\": {\n"
+ " \"type\": \"text\",\n"
+ " \"analyzer\": \"test\"\n"
+ " }\n"
+ " }\n"
+ " }}",
XContentType.JSON
+ " }"
)
.get();
logger.info("--> indexing a simple document");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
Expand Down Expand Up @@ -115,16 +114,14 @@ public void testOneNodeRecoverFromGateway() throws Exception {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("appAccountIds")
.field("type", "text")
.endObject()
.endObject()
.endObject()
.endObject()
);
assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON));
assertAcked(prepareCreate("test").setMapping(mapping));

client().prepareIndex("test")
.setId("10990239")
Expand Down Expand Up @@ -212,7 +209,6 @@ public void testSingleNodeNoFlush() throws Exception {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field")
.field("type", "text")
Expand All @@ -222,14 +218,13 @@ public void testSingleNodeNoFlush() throws Exception {
.endObject()
.endObject()
.endObject()
.endObject()
);
// note: default replica settings are tied to #data nodes-1 which is 0 here. We can do with 1 in this test.
int numberOfShards = numberOfShards();
assertAcked(
prepareCreate("test").setSettings(
Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numberOfShards()).put(SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 1))
).addMapping("type1", mapping, XContentType.JSON)
).setMapping(mapping)
);

int value1Docs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,15 @@ public void testGetDocWithMultivaluedFields() throws Exception {
String mapping1 = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type1")
.startObject("properties")
.startObject("field")
.field("type", "text")
.field("store", true)
.endObject()
.endObject()
.endObject()
.endObject()
);
assertAcked(prepareCreate("test").addMapping("type1", mapping1, XContentType.JSON));
assertAcked(prepareCreate("test").setMapping(mapping1));
ensureGreen();

GetResponse response = client().prepareGet("test", "1").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.search.aggregations.AggregationBuilders;
import org.opensearch.search.aggregations.Aggregator.SubAggCollectionMode;
Expand Down Expand Up @@ -81,17 +80,15 @@ public void testDynamicTemplateCopyTo() throws Exception {
public void testDynamicObjectCopyTo() throws Exception {
String mapping = Strings.toString(
jsonBuilder().startObject()
.startObject("_doc")
.startObject("properties")
.startObject("foo")
.field("type", "text")
.field("copy_to", "root.top.child")
.endObject()
.endObject()
.endObject()
.endObject()
);
assertAcked(client().admin().indices().prepareCreate("test-idx").addMapping("_doc", mapping, XContentType.JSON));
assertAcked(client().admin().indices().prepareCreate("test-idx").setMapping(mapping));
client().prepareIndex("test-idx").setId("1").setSource("foo", "bar").get();
client().admin().indices().prepareRefresh("test-idx").execute().actionGet();
SearchResponse response = client().prepareSearch("test-idx").setQuery(QueryBuilders.termQuery("root.top.child", "bar")).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.opensearch.action.ActionListener;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand All @@ -49,14 +48,10 @@
import static org.hamcrest.Matchers.emptyIterable;

public class ConcurrentDynamicTemplateIT extends OpenSearchIntegTestCase {
private final String mappingType = "test-mapping";

// see #3544
public void testConcurrentDynamicMapping() throws Exception {
final String fieldName = "field";
final String mapping = "{ \""
+ mappingType
+ "\": {"
final String mapping = "{ "
+ "\"dynamic_templates\": ["
+ "{ \""
+ fieldName
Expand All @@ -65,14 +60,14 @@ public void testConcurrentDynamicMapping() throws Exception {
+ "\"mapping\": {"
+ "\"type\": \"text\","
+ "\"store\": true,"
+ "\"analyzer\": \"whitespace\" } } } ] } }";
+ "\"analyzer\": \"whitespace\" } } } ] }";
// The 'fieldNames' array is used to help with retrieval of index terms
// after testing

int iters = scaledRandomIntBetween(5, 15);
for (int i = 0; i < iters; i++) {
cluster().wipeIndices("test");
assertAcked(prepareCreate("test").addMapping(mappingType, mapping, XContentType.JSON));
assertAcked(prepareCreate("test").setMapping(mapping));
int numDocs = scaledRandomIntBetween(10, 100);
final CountDownLatch latch = new CountDownLatch(numDocs);
final List<Throwable> throwable = new CopyOnWriteArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testUpdateMappingWithoutType() {
.indices()
.prepareCreate("test")
.setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0))
.addMapping("_doc", "{\"_doc\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
.setMapping("{\"properties\":{\"body\":{\"type\":\"text\"}}}")
.execute()
.actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
Expand Down Expand Up @@ -196,7 +196,7 @@ public void testUpdateMappingWithConflicts() {
.indices()
.prepareCreate("test")
.setSettings(Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0))
.addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
.setMapping("{\"properties\":{\"body\":{\"type\":\"text\"}}}")
.execute()
.actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
Expand All @@ -221,7 +221,7 @@ public void testUpdateMappingWithNormsConflicts() {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": false }}}}", XContentType.JSON)
.setMapping("{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": false }}}")
.execute()
.actionGet();
try {
Expand All @@ -248,11 +248,7 @@ public void testUpdateMappingNoChanges() {
.indices()
.prepareCreate("test")
.setSettings(Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0))
.addMapping(
MapperService.SINGLE_MAPPING_NAME,
"{\"" + MapperService.SINGLE_MAPPING_NAME + "\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}",
XContentType.JSON
)
.setMapping("{\"properties\":{\"body\":{\"type\":\"text\"}}}")
.execute()
.actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.MockEngineFactoryPlugin;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.indices.IndicesService;
Expand Down Expand Up @@ -104,7 +103,6 @@ public void testBreakerWithRandomExceptions() throws IOException, InterruptedExc
.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject("properties")
.startObject("test-str")
.field("type", "keyword")
Expand All @@ -115,7 +113,6 @@ public void testBreakerWithRandomExceptions() throws IOException, InterruptedExc
.field("type", randomFrom(Arrays.asList("float", "long", "double", "short", "integer")))
.endObject() // test-num
.endObject() // properties
.endObject() // type
.endObject()
);
final double topLevelRate;
Expand Down Expand Up @@ -149,7 +146,7 @@ public void testBreakerWithRandomExceptions() throws IOException, InterruptedExc
.indices()
.prepareCreate("test")
.setSettings(settings)
.addMapping("type", mapping, XContentType.JSON)
.setMapping(mapping)
.execute()
.actionGet();
final int numDocs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.rest.RestStatus;
Expand Down Expand Up @@ -305,17 +304,15 @@ public void testOpenCloseWithDocs() throws IOException, ExecutionException, Inte
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject("properties")
.startObject("test")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.endObject()
);

assertAcked(client().admin().indices().prepareCreate("test").addMapping("type", mapping, XContentType.JSON));
assertAcked(client().admin().indices().prepareCreate("test").setMapping(mapping));
ensureGreen();
int docs = between(10, 100);
IndexRequestBuilder[] builder = new IndexRequestBuilder[docs];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,9 @@ public void testMultiIndex() throws Exception {

public void testCompletionFieldsParam() throws Exception {
assertAcked(
prepareCreate("test1").addMapping(
"_doc",
prepareCreate("test1").setMapping(
"{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}"
+ ",\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}",
XContentType.JSON
+ ",\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}"
)
);
ensureGreen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.mockito.internal.util.collections.Sets;
Expand All @@ -63,11 +61,7 @@ public void testVariousPartitionSizes() throws Exception {
.put("index.number_of_routing_shards", shards)
.put("index.routing_partition_size", partitionSize)
)
.addMapping(
MapperService.SINGLE_MAPPING_NAME,
"{\"" + MapperService.SINGLE_MAPPING_NAME + "\":{\"_routing\":{\"required\":true}}}",
XContentType.JSON
)
.setMapping("{\"_routing\":{\"required\":true}}")
.execute()
.actionGet();
ensureGreen();
Expand Down Expand Up @@ -101,11 +95,7 @@ public void testShrinking() throws Exception {
.put("index.number_of_replicas", numberOfReplicas())
.put("index.routing_partition_size", partitionSize)
)
.addMapping(
MapperService.SINGLE_MAPPING_NAME,
"{\"" + MapperService.SINGLE_MAPPING_NAME + "\":{\"_routing\":{\"required\":true}}}",
XContentType.JSON
)
.setMapping("{\"_routing\":{\"required\":true}}}")
.execute()
.actionGet();
ensureGreen();
Expand Down
Loading

0 comments on commit b619a05

Please sign in to comment.