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] types from CreateIndexRequest and companion Builder's mapping method #2498

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -73,7 +73,7 @@ public void testCustomWordDelimiterQueryString() {
.put("analysis.filter.custom_word_delimiter.split_on_numerics", "false")
.put("analysis.filter.custom_word_delimiter.stem_english_possessive", "false")
)
.addMapping("type1", "field1", "type=text,analyzer=my_analyzer", "field2", "type=text,analyzer=my_analyzer")
.setMapping("field1", "type=text,analyzer=my_analyzer", "field2", "type=text,analyzer=my_analyzer")
);

client().prepareIndex("test").setId("1").setSource("field1", "foo bar baz", "field2", "not needed").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void testMultiPhraseCutoff() throws IOException {
* query. We cut off and extract terms if there are more than 16 terms in the query
*/
assertAcked(
prepareCreate("test").addMapping(
"test",
prepareCreate("test").setMapping(
"body",
"type=text,analyzer=custom_analyzer," + "search_analyzer=custom_analyzer,term_vector=with_positions_offsets"
)
Expand Down Expand Up @@ -225,8 +224,7 @@ public void testSynonyms() throws IOException {

assertAcked(
prepareCreate("test").setSettings(builder.build())
.addMapping(
"type1",
.setMapping(
"field1",
"type=text,term_vector=with_positions_offsets,search_analyzer=synonym," + "analyzer=standard,index_options=offsets"
)
Expand Down Expand Up @@ -335,8 +333,7 @@ public void testPhrasePrefix() throws IOException {

assertAcked(
prepareCreate("second_test_index").setSettings(builder.build())
.addMapping(
"doc",
.setMapping(
"field4",
"type=text,term_vector=with_positions_offsets,analyzer=synonym",
"field3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void testScore() throws Exception {
}

public void testDateMethods() throws Exception {
OpenSearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "date0", "type=date", "date1", "type=date"));
OpenSearchAssertions.assertAcked(prepareCreate("test").setMapping("date0", "type=date", "date1", "type=date"));
ensureGreen("test");
indexRandom(
true,
Expand Down Expand Up @@ -188,7 +188,7 @@ public void testDateMethods() throws Exception {
}

public void testDateObjectMethods() throws Exception {
OpenSearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "date0", "type=date", "date1", "type=date"));
OpenSearchAssertions.assertAcked(prepareCreate("test").setMapping("date0", "type=date", "date1", "type=date"));
ensureGreen("test");
indexRandom(
true,
Expand Down Expand Up @@ -219,7 +219,7 @@ public void testDateObjectMethods() throws Exception {

public void testMultiValueMethods() throws Exception {
OpenSearchAssertions.assertAcked(
prepareCreate("test").addMapping("doc", "double0", "type=double", "double1", "type=double", "double2", "type=double")
prepareCreate("test").setMapping("double0", "type=double", "double1", "type=double", "double2", "type=double")
);
ensureGreen("test");

Expand Down Expand Up @@ -322,7 +322,7 @@ public void testMultiValueMethods() throws Exception {
}

public void testInvalidDateMethodCall() throws Exception {
OpenSearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "double", "type=double"));
OpenSearchAssertions.assertAcked(prepareCreate("test").setMapping("double", "type=double"));
ensureGreen("test");
indexRandom(true, client().prepareIndex("test").setId("1").setSource("double", "178000000.0"));
try {
Expand All @@ -343,7 +343,7 @@ public void testInvalidDateMethodCall() throws Exception {
}

public void testSparseField() throws Exception {
OpenSearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "x", "type=long", "y", "type=long"));
OpenSearchAssertions.assertAcked(prepareCreate("test").setMapping("x", "type=long", "y", "type=long"));
ensureGreen("test");
indexRandom(
true,
Expand Down Expand Up @@ -528,7 +528,7 @@ public void testSpecialValueVariable() throws Exception {

public void testStringSpecialValueVariable() throws Exception {
// i.e. expression script for term aggregations, which is not allowed
assertAcked(client().admin().indices().prepareCreate("test").addMapping("doc", "text", "type=keyword").get());
assertAcked(client().admin().indices().prepareCreate("test").setMapping("text", "type=keyword").get());
ensureGreen("test");
indexRandom(
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testPercolatorQuery() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "id", "type=keyword", "field1", "type=keyword", "field2", "type=keyword", "query", "type=percolator")
.setMapping("id", "type=keyword", "field1", "type=keyword", "field2", "type=keyword", "query", "type=percolator")
);

client().prepareIndex("test")
Expand Down Expand Up @@ -183,8 +183,7 @@ public void testPercolatorRangeQueries() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping(
"type",
.setMapping(
"field1",
"type=long",
"field2",
Expand Down Expand Up @@ -315,17 +314,7 @@ public void testPercolatorGeoQueries() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping(
"type",
"id",
"type=keyword",
"field1",
"type=geo_point",
"field2",
"type=geo_shape",
"query",
"type=percolator"
)
.setMapping("id", "type=keyword", "field1", "type=geo_point", "field2", "type=geo_shape", "query", "type=percolator")
);

client().prepareIndex("test")
Expand Down Expand Up @@ -380,7 +369,7 @@ public void testPercolatorQueryExistingDocument() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "id", "type=keyword", "field1", "type=keyword", "field2", "type=keyword", "query", "type=percolator")
.setMapping("id", "type=keyword", "field1", "type=keyword", "field2", "type=keyword", "query", "type=percolator")
);

client().prepareIndex("test")
Expand Down Expand Up @@ -438,7 +427,7 @@ public void testPercolatorQueryExistingDocumentSourceDisabled() throws Exception
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "_source", "enabled=false", "field1", "type=keyword", "query", "type=percolator")
.setMapping("_source", "enabled=false", "field1", "type=keyword", "query", "type=percolator")
);

client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()).get();
Expand All @@ -459,7 +448,7 @@ public void testPercolatorSpecificQueries() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "id", "type=keyword", "field1", "type=text", "field2", "type=text", "query", "type=percolator")
.setMapping("id", "type=keyword", "field1", "type=text", "field2", "type=text", "query", "type=percolator")
);

client().prepareIndex("test")
Expand Down Expand Up @@ -565,7 +554,7 @@ public void testPercolatorQueryWithHighlighting() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "id", "type=keyword", "field1", fieldMapping.toString(), "query", "type=percolator")
.setMapping("id", "type=keyword", "field1", fieldMapping.toString(), "query", "type=percolator")
);
client().prepareIndex("test")
.setId("1")
Expand Down Expand Up @@ -810,7 +799,7 @@ public void testTakePositionOffsetGapIntoAccount() throws Exception {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("type", "field", "type=text,position_increment_gap=5", "query", "type=percolator")
.setMapping("field", "type=text,position_increment_gap=5", "query", "type=percolator")
);
client().prepareIndex("test")
.setId("1")
Expand All @@ -832,13 +821,13 @@ public void testTakePositionOffsetGapIntoAccount() throws Exception {
public void testManyPercolatorFields() throws Exception {
String queryFieldName = randomAlphaOfLength(8);
assertAcked(
client().admin().indices().prepareCreate("test1").addMapping("type", queryFieldName, "type=percolator", "field", "type=keyword")
client().admin().indices().prepareCreate("test1").setMapping(queryFieldName, "type=percolator", "field", "type=keyword")
);
assertAcked(
client().admin()
.indices()
.prepareCreate("test2")
.addMapping("type", queryFieldName, "type=percolator", "second_query_field", "type=percolator", "field", "type=keyword")
.setMapping(queryFieldName, "type=percolator", "second_query_field", "type=percolator", "field", "type=keyword")
);
assertAcked(
client().admin()
Expand Down Expand Up @@ -867,7 +856,7 @@ public void testManyPercolatorFields() throws Exception {
public void testWithMultiplePercolatorFields() throws Exception {
String queryFieldName = randomAlphaOfLength(8);
assertAcked(
client().admin().indices().prepareCreate("test1").addMapping("type", queryFieldName, "type=percolator", "field", "type=keyword")
client().admin().indices().prepareCreate("test1").setMapping(queryFieldName, "type=percolator", "field", "type=keyword")
);
assertAcked(
client().admin()
Expand Down Expand Up @@ -1130,7 +1119,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception {
}

public void testPercolatorQueryViaMultiSearch() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test").addMapping("type", "field1", "type=text", "query", "type=percolator"));
assertAcked(client().admin().indices().prepareCreate("test").setMapping("field1", "type=text", "query", "type=percolator"));

client().prepareIndex("test")
.setId("1")
Expand Down Expand Up @@ -1248,7 +1237,7 @@ public void testDisallowExpensiveQueries() throws IOException {
client().admin()
.indices()
.prepareCreate("test")
.addMapping("_doc", "id", "type=keyword", "field1", "type=keyword", "query", "type=percolator")
.setMapping("id", "type=keyword", "field1", "type=keyword", "query", "type=percolator")
);

client().prepareIndex("test")
Expand Down Expand Up @@ -1298,7 +1287,7 @@ public void testDisallowExpensiveQueries() throws IOException {

public void testWrappedWithConstantScore() throws Exception {

assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", "d", "type=date", "q", "type=percolator"));
assertAcked(client().admin().indices().prepareCreate("test").setMapping("d", "type=date", "q", "type=percolator"));

client().prepareIndex("test")
.setId("1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
}

public void testPercolateScriptQuery() throws IOException {
client().admin().indices().prepareCreate("index").addMapping("type", "query", "type=percolator").get();
client().admin().indices().prepareCreate("index").setMapping("query", "type=percolator").get();
client().prepareIndex("index")
.setId("1")
.setSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.plugin.mapper.MapperSizePlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
Expand Down Expand Up @@ -122,7 +121,7 @@ private void assertSizeMappingEnabled(String index, boolean enabled) throws IOEx
}

public void testBasic() throws Exception {
assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, "_size", "enabled=true"));
assertAcked(prepareCreate("test").setMapping("_size", "enabled=true"));
final String source = "{\"f\":10}";
indexRandom(true, client().prepareIndex("test").setId("1").setSource(source, XContentType.JSON));
GetResponse getResponse = client().prepareGet("test", "1").setStoredFields("_size").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.SegmentsStats;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.shard.IndexShard;
Expand Down Expand Up @@ -527,7 +526,7 @@ public void testCreateShrinkWithIndexSort() throws Exception {
.put("sort.order", "desc")
.put("number_of_shards", 8)
.put("number_of_replicas", 0)
).addMapping(MapperService.SINGLE_MAPPING_NAME, "id", "type=keyword,doc_values=true").get();
).setMapping("id", "type=keyword,doc_values=true").get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source")
.setId(Integer.toString(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.SegmentsStats;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.index.shard.IndexShard;
Expand Down Expand Up @@ -136,12 +135,12 @@ private void splitToN(int sourceShards, int firstSplitShards, int secondSplitSha
int numRoutingShards = MetadataCreateIndexService.calculateNumRoutingShards(secondSplitShards, Version.CURRENT) - 1;
settings.put("index.routing_partition_size", randomIntBetween(1, numRoutingShards));
if (useNested) {
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "_routing", "required=true", "nested1", "type=nested");
createInitialIndex.setMapping("_routing", "required=true", "nested1", "type=nested");
} else {
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "_routing", "required=true");
createInitialIndex.setMapping("_routing", "required=true");
}
} else if (useNested) {
createInitialIndex.addMapping(MapperService.SINGLE_MAPPING_NAME, "nested1", "type=nested");
createInitialIndex.setMapping("nested1", "type=nested");
}
logger.info("use routing {} use mixed routing {} use nested {}", useRouting, useMixedRouting, useNested);
createInitialIndex.setSettings(settings).get();
Expand Down Expand Up @@ -523,7 +522,7 @@ public void testCreateSplitWithIndexSort() throws Exception {
.put("sort.order", "desc")
.put("number_of_shards", 2)
.put("number_of_replicas", 0)
).addMapping(MapperService.SINGLE_MAPPING_NAME, "id", "type=keyword,doc_values=true").get();
).setMapping("id", "type=keyword,doc_values=true").get();
for (int i = 0; i < 20; i++) {
client().prepareIndex("source")
.setId(Integer.toString(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void testSearchIdle() throws Exception {
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5))
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numOfReplicas)
.put(IndexSettings.INDEX_SEARCH_IDLE_AFTER.getKey(), TimeValue.timeValueMillis(randomIntBetween(50, 500)));
assertAcked(prepareCreate("test").setSettings(settings).addMapping("_doc", "created_date", "type=date,format=yyyy-MM-dd"));
assertAcked(prepareCreate("test").setSettings(settings).setMapping("created_date", "type=date,format=yyyy-MM-dd"));
ensureGreen("test");
assertBusy(() -> {
for (String node : internalCluster().nodesInclude("test")) {
Expand Down
Loading