diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/opensearch/plugin/noop/action/bulk/RestNoopBulkAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/opensearch/plugin/noop/action/bulk/RestNoopBulkAction.java index 771f13d7d979b..62123870f0099 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/opensearch/plugin/noop/action/bulk/RestNoopBulkAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/opensearch/plugin/noop/action/bulk/RestNoopBulkAction.java @@ -116,7 +116,7 @@ private static class BulkRestBuilderListener extends RestBuilderListener[] expectedIds(int numDocs) { return IntStream.rangeClosed(1, numDocs).boxed().map(n -> hasId(n.toString())).>toArray(Matcher[]::new); } - private MultiGetRequest indexDocs( - BulkProcessor processor, - int numDocs, - String localIndex, - String localType, - String globalIndex, - String globalPipeline - ) throws Exception { + private MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, String localIndex, String globalIndex, String globalPipeline) + throws Exception { MultiGetRequest multiGetRequest = new MultiGetRequest(); for (int i = 1; i <= numDocs; i++) { if (randomBoolean()) { processor.add( - new IndexRequest(localIndex, localType, Integer.toString(i)).source( - XContentType.JSON, - "field", - randomRealisticUnicodeOfLengthBetween(1, 30) - ) + new IndexRequest(localIndex).id(Integer.toString(i)) + .source(XContentType.JSON, "field", randomRealisticUnicodeOfLengthBetween(1, 30)) ); } else { - BytesArray data = bytesBulkRequest(localIndex, localType, i); + BytesArray data = bytesBulkRequest(localIndex, i); processor.add(data, globalIndex, globalPipeline, XContentType.JSON); } multiGetRequest.add(localIndex, Integer.toString(i)); @@ -422,17 +411,13 @@ private MultiGetRequest indexDocs( return multiGetRequest; } - private static BytesArray bytesBulkRequest(String localIndex, String localType, int id) throws IOException { + private static BytesArray bytesBulkRequest(String localIndex, int id) throws IOException { XContentBuilder action = jsonBuilder().startObject().startObject("index"); if (localIndex != null) { action.field("_index", localIndex); } - if (localType != null) { - action.field("_type", localType); - } - action.field("_id", Integer.toString(id)); action.endObject().endObject(); @@ -443,7 +428,7 @@ private static BytesArray bytesBulkRequest(String localIndex, String localType, } private MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) throws Exception { - return indexDocs(processor, numDocs, "test", null, null, null); + return indexDocs(processor, numDocs, "test", null, null); } private static void assertResponseItems(List bulkItemResponses, int numDocs) { diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java index 632179b1b7cf1..999c2a0e7643b 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/CrudIT.java @@ -108,7 +108,6 @@ public void testDelete() throws IOException { } DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); assertEquals("index", deleteResponse.getIndex()); - assertEquals("_doc", deleteResponse.getType()); assertEquals(docId, deleteResponse.getId()); assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult()); } @@ -118,7 +117,6 @@ public void testDelete() throws IOException { DeleteRequest deleteRequest = new DeleteRequest("index", docId); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); assertEquals("index", deleteResponse.getIndex()); - assertEquals("_doc", deleteResponse.getType()); assertEquals(docId, deleteResponse.getId()); assertEquals(DocWriteResponse.Result.NOT_FOUND, deleteResponse.getResult()); } @@ -157,7 +155,6 @@ public void testDelete() throws IOException { DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(13); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); assertEquals("index", deleteResponse.getIndex()); - assertEquals("_doc", deleteResponse.getType()); assertEquals(docId, deleteResponse.getId()); assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult()); } @@ -194,7 +191,6 @@ public void testDelete() throws IOException { DeleteRequest deleteRequest = new DeleteRequest("index", docId).routing("foo"); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); assertEquals("index", deleteResponse.getIndex()); - assertEquals("_doc", deleteResponse.getType()); assertEquals(docId, deleteResponse.getId()); assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult()); } @@ -440,8 +436,8 @@ public void testMultiGet() throws IOException { public void testMultiGetWithIds() throws IOException { BulkRequest bulk = new BulkRequest(); bulk.setRefreshPolicy(RefreshPolicy.IMMEDIATE); - bulk.add(new IndexRequest("index", "id1").source("{\"field\":\"value1\"}", XContentType.JSON)); - bulk.add(new IndexRequest("index", "id2").source("{\"field\":\"value2\"}", XContentType.JSON)); + bulk.add(new IndexRequest("index").id("id1").source("{\"field\":\"value1\"}", XContentType.JSON)); + bulk.add(new IndexRequest("index").id("id2").source("{\"field\":\"value2\"}", XContentType.JSON)); MultiGetRequest multiGetRequest = new MultiGetRequest(); multiGetRequest.add("index", "id1"); @@ -534,7 +530,6 @@ public void testIndex() throws IOException { assertEquals(RestStatus.CREATED, indexResponse.status()); assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult()); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertTrue(Strings.hasLength(indexResponse.getId())); assertEquals(1L, indexResponse.getVersion()); assertNotNull(indexResponse.getShardId()); @@ -554,7 +549,6 @@ public void testIndex() throws IOException { IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); assertEquals(RestStatus.CREATED, indexResponse.status()); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals("id", indexResponse.getId()); assertEquals(1L, indexResponse.getVersion()); @@ -564,7 +558,6 @@ public void testIndex() throws IOException { indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); assertEquals(RestStatus.OK, indexResponse.status()); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals("id", indexResponse.getId()); assertEquals(2L, indexResponse.getVersion()); @@ -622,7 +615,6 @@ public void testIndex() throws IOException { IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); assertEquals(RestStatus.CREATED, indexResponse.status()); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals("external_version_type", indexResponse.getId()); assertEquals(12L, indexResponse.getVersion()); } @@ -634,7 +626,6 @@ public void testIndex() throws IOException { IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); assertEquals(RestStatus.CREATED, indexResponse.status()); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals("with_create_op_type", indexResponse.getId()); OpenSearchStatusException exception = expectThrows( @@ -662,7 +653,7 @@ public void testUpdate() throws IOException { ); assertEquals(RestStatus.NOT_FOUND, exception.status()); assertEquals( - "OpenSearch exception [type=document_missing_exception, reason=[_doc][does_not_exist]: document missing]", + "OpenSearch exception [type=document_missing_exception, reason=[does_not_exist]: document missing]", exception.getMessage() ); } @@ -787,7 +778,6 @@ public void testUpdate() throws IOException { UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync); assertEquals(RestStatus.CREATED, updateResponse.status()); assertEquals("index", updateResponse.getIndex()); - assertEquals("_doc", updateResponse.getType()); assertEquals("with_upsert", updateResponse.getId()); GetResult getResult = updateResponse.getGetResult(); assertEquals(1L, updateResponse.getVersion()); @@ -802,7 +792,6 @@ public void testUpdate() throws IOException { UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync); assertEquals(RestStatus.CREATED, updateResponse.status()); assertEquals("index", updateResponse.getIndex()); - assertEquals("_doc", updateResponse.getType()); assertEquals("with_doc_as_upsert", updateResponse.getId()); GetResult getResult = updateResponse.getGetResult(); assertEquals(1L, updateResponse.getVersion()); @@ -818,7 +807,6 @@ public void testUpdate() throws IOException { UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync); assertEquals(RestStatus.CREATED, updateResponse.status()); assertEquals("index", updateResponse.getIndex()); - assertEquals("_doc", updateResponse.getType()); assertEquals("with_scripted_upsert", updateResponse.getId()); GetResult getResult = updateResponse.getGetResult(); @@ -1039,7 +1027,6 @@ public void testUrlEncode() throws IOException { indexRequest.source("field", "value"); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals(expectedIndex, indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals("id#1", indexResponse.getId()); } { @@ -1056,7 +1043,6 @@ public void testUrlEncode() throws IOException { indexRequest.source("field", "value"); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals(docId, indexResponse.getId()); } { @@ -1079,7 +1065,6 @@ public void testParamsEncode() throws IOException { indexRequest.routing(routing); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals("index", indexResponse.getIndex()); - assertEquals("_doc", indexResponse.getType()); assertEquals("id", indexResponse.getId()); } { diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java index 89881c4e01fe2..32c6cde0725b4 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/RequestConvertersTests.java @@ -348,18 +348,6 @@ public void testDelete() { assertNull(request.getEntity()); } - public void testDeleteWithType() { - String index = randomAlphaOfLengthBetween(3, 10); - String type = randomAlphaOfLengthBetween(3, 10); - String id = randomAlphaOfLengthBetween(3, 10); - DeleteRequest deleteRequest = new DeleteRequest(index, type, id); - - Request request = RequestConverters.delete(deleteRequest); - assertEquals(HttpDelete.METHOD_NAME, request.getMethod()); - assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint()); - assertNull(request.getEntity()); - } - public void testExists() { getAndExistsTest(RequestConverters::exists, HttpHead.METHOD_NAME); } @@ -445,9 +433,6 @@ public void testReindex() throws IOException { if (randomBoolean()) { reindexRequest.setSourceBatchSize(randomInt(100)); } - if (randomBoolean()) { - reindexRequest.setDestDocType("tweet_and_doc"); - } if (randomBoolean()) { reindexRequest.setDestOpType("create"); } @@ -752,49 +737,6 @@ public void testIndex() throws IOException { } } - public void testIndexWithType() throws IOException { - String index = randomAlphaOfLengthBetween(3, 10); - String type = randomAlphaOfLengthBetween(3, 10); - IndexRequest indexRequest = new IndexRequest(index, type); - String id = randomBoolean() ? randomAlphaOfLengthBetween(3, 10) : null; - indexRequest.id(id); - - String method = HttpPost.METHOD_NAME; - if (id != null) { - method = HttpPut.METHOD_NAME; - if (randomBoolean()) { - indexRequest.opType(DocWriteRequest.OpType.CREATE); - } - } - XContentType xContentType = randomFrom(XContentType.values()); - int nbFields = randomIntBetween(0, 10); - try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { - builder.startObject(); - for (int i = 0; i < nbFields; i++) { - builder.field("field_" + i, i); - } - builder.endObject(); - indexRequest.source(builder); - } - - Request request = RequestConverters.index(indexRequest); - if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) { - assertEquals("/" + index + "/" + type + "/" + id + "/_create", request.getEndpoint()); - } else if (id != null) { - assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint()); - } else { - assertEquals("/" + index + "/" + type, request.getEndpoint()); - } - assertEquals(method, request.getMethod()); - - HttpEntity entity = request.getEntity(); - assertTrue(entity instanceof NByteArrayEntity); - assertEquals(indexRequest.getContentType().mediaTypeWithoutParameters(), entity.getContentType().getValue()); - try (XContentParser parser = createParser(xContentType.xContent(), entity.getContent())) { - assertEquals(nbFields, parser.map().size()); - } - } - public void testUpdate() throws IOException { XContentType xContentType = randomFrom(XContentType.values()); @@ -903,23 +845,6 @@ private static void setRandomIfSeqNoAndTerm(DocWriteRequest request, Map { UpdateRequest updateRequest = new UpdateRequest(); @@ -1014,7 +939,6 @@ public void testBulk() throws IOException { assertEquals(originalRequest.opType(), parsedRequest.opType()); assertEquals(originalRequest.index(), parsedRequest.index()); - assertEquals(originalRequest.type(), parsedRequest.type()); assertEquals(originalRequest.id(), parsedRequest.id()); assertEquals(originalRequest.routing(), parsedRequest.routing()); assertEquals(originalRequest.version(), parsedRequest.version()); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/TasksIT.java b/client/rest-high-level/src/test/java/org/opensearch/client/TasksIT.java index 0db8ee4406c8c..d987e786fff76 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/TasksIT.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/TasksIT.java @@ -117,7 +117,7 @@ public void testGetValidTask() throws Exception { } org.opensearch.tasks.TaskInfo info = taskResponse.getTaskInfo(); assertTrue(info.isCancellable()); - assertEquals("reindex from [source1] to [dest][_doc]", info.getDescription()); + assertEquals("reindex from [source1] to [dest]", info.getDescription()); assertEquals("indices:data/write/reindex", info.getAction()); if (taskResponse.isCompleted() == false) { assertBusy(checkTaskCompletionStatus(client(), taskId)); diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DateIndexNameProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DateIndexNameProcessorTests.java index 820ef3a8ee9c2..1ff2aa7fdd629 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DateIndexNameProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DateIndexNameProcessorTests.java @@ -60,7 +60,6 @@ public void testJavaPattern() throws Exception { ); IngestDocument document = new IngestDocument( "_index", - "_type", "_id", null, null, @@ -83,7 +82,6 @@ public void testTAI64N() throws Exception { ); IngestDocument document = new IngestDocument( "_index", - "_type", "_id", null, null, @@ -104,19 +102,11 @@ public void testUnixMs() throws Exception { "m", "yyyyMMdd" ); - IngestDocument document = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("_field", "1000500") - ); + IngestDocument document = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("_field", "1000500")); dateProcessor.execute(document); assertThat(document.getSourceAndMetadata().get("_index"), equalTo("")); - document = new IngestDocument("_index", "_type", "_id", null, null, null, Collections.singletonMap("_field", 1000500L)); + document = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("_field", 1000500L)); dateProcessor.execute(document); assertThat(document.getSourceAndMetadata().get("_index"), equalTo("")); } @@ -131,15 +121,7 @@ public void testUnix() throws Exception { "m", "yyyyMMdd" ); - IngestDocument document = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("_field", "1000.5") - ); + IngestDocument document = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("_field", "1000.5")); dateProcessor.execute(document); assertThat(document.getSourceAndMetadata().get("_index"), equalTo("")); } @@ -160,7 +142,7 @@ public void testTemplatedFields() throws Exception { indexNameFormat ); - IngestDocument document = new IngestDocument("_index", "_type", "_id", null, null, null, Collections.singletonMap("_field", date)); + IngestDocument document = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("_field", date)); dateProcessor.execute(document); assertThat( diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DissectProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DissectProcessorTests.java index 6f44b81e7b43b..ca0c0df40f009 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DissectProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/DissectProcessorTests.java @@ -55,7 +55,6 @@ public class DissectProcessorTests extends OpenSearchTestCase { public void testMatch() { IngestDocument ingestDocument = new IngestDocument( "_index", - "_type", "_id", null, null, @@ -72,7 +71,6 @@ public void testMatch() { public void testMatchOverwrite() { IngestDocument ingestDocument = new IngestDocument( "_index", - "_type", "_id", null, null, @@ -90,7 +88,6 @@ public void testMatchOverwrite() { public void testAdvancedMatch() { IngestDocument ingestDocument = new IngestDocument( "_index", - "_type", "_id", null, null, @@ -116,7 +113,6 @@ public void testAdvancedMatch() { public void testMiss() { IngestDocument ingestDocument = new IngestDocument( "_index", - "_type", "_id", null, null, diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/ForEachProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/ForEachProcessorTests.java index f0c61700f4db0..8db3cefc3a6fd 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/ForEachProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/ForEachProcessorTests.java @@ -61,15 +61,7 @@ public void testExecuteWithAsyncProcessor() throws Exception { values.add("foo"); values.add("bar"); values.add("baz"); - IngestDocument ingestDocument = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("values", values) - ); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("values", values)); ForEachProcessor processor = new ForEachProcessor("_tag", null, "values", new AsyncUpperCaseProcessor("_ingest._value"), false); processor.execute(ingestDocument, (result, e) -> {}); @@ -87,7 +79,6 @@ public void testExecuteWithAsyncProcessor() throws Exception { public void testExecuteWithFailure() throws Exception { IngestDocument ingestDocument = new IngestDocument( "_index", - "_type", "_id", null, null, @@ -132,15 +123,7 @@ public void testMetadataAvailable() throws Exception { List> values = new ArrayList<>(); values.add(new HashMap<>()); values.add(new HashMap<>()); - IngestDocument ingestDocument = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("values", values) - ); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("values", values)); TestProcessor innerProcessor = new TestProcessor(id -> { id.setFieldValue("_ingest._value.index", id.getSourceAndMetadata().get("_index")); @@ -152,10 +135,8 @@ public void testMetadataAvailable() throws Exception { assertThat(innerProcessor.getInvokedCounter(), equalTo(2)); assertThat(ingestDocument.getFieldValue("values.0.index", String.class), equalTo("_index")); - assertThat(ingestDocument.getFieldValue("values.0.type", String.class), equalTo("_type")); assertThat(ingestDocument.getFieldValue("values.0.id", String.class), equalTo("_id")); assertThat(ingestDocument.getFieldValue("values.1.index", String.class), equalTo("_index")); - assertThat(ingestDocument.getFieldValue("values.1.type", String.class), equalTo("_type")); assertThat(ingestDocument.getFieldValue("values.1.id", String.class), equalTo("_id")); } @@ -170,7 +151,7 @@ public void testRestOfTheDocumentIsAvailable() throws Exception { document.put("values", values); document.put("flat_values", new ArrayList<>()); document.put("other", "value"); - IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", null, null, null, document); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, document); ForEachProcessor processor = new ForEachProcessor( "_tag", @@ -220,15 +201,7 @@ public String getDescription() { int numValues = randomIntBetween(1, 10000); List values = IntStream.range(0, numValues).mapToObj(i -> "").collect(Collectors.toList()); - IngestDocument ingestDocument = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("values", values) - ); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("values", values)); ForEachProcessor processor = new ForEachProcessor("_tag", null, "values", innerProcessor, false); processor.execute(ingestDocument, (result, e) -> {}); @@ -244,15 +217,7 @@ public void testModifyFieldsOutsideArray() throws Exception { values.add("string"); values.add(1); values.add(null); - IngestDocument ingestDocument = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("values", values) - ); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("values", values)); TemplateScript.Factory template = new TestTemplateService.MockTemplateScript.Factory("errors"); @@ -290,7 +255,7 @@ public void testScalarValueAllowsUnderscoreValueFieldToRemainAccessible() throws Map source = new HashMap<>(); source.put("_value", "new_value"); source.put("values", values); - IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", null, null, null, source); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, source); TestProcessor processor = new TestProcessor( doc -> doc.setFieldValue("_ingest._value", doc.getFieldValue("_source._value", String.class)) @@ -320,15 +285,7 @@ public void testNestedForEach() throws Exception { value.put("values2", innerValues); values.add(value); - IngestDocument ingestDocument = new IngestDocument( - "_index", - "_type", - "_id", - null, - null, - null, - Collections.singletonMap("values1", values) - ); + IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("values1", values)); TestProcessor testProcessor = new TestProcessor( doc -> doc.setFieldValue("_ingest._value", doc.getFieldValue("_ingest._value", String.class).toUpperCase(Locale.ENGLISH)) @@ -352,7 +309,7 @@ public void testNestedForEach() throws Exception { } public void testIgnoreMissing() throws Exception { - IngestDocument originalIngestDocument = new IngestDocument("_index", "_type", "_id", null, null, null, Collections.emptyMap()); + IngestDocument originalIngestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.emptyMap()); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); TestProcessor testProcessor = new TestProcessor(doc -> {}); ForEachProcessor processor = new ForEachProcessor("_tag", null, "_ingest._value", testProcessor, true); @@ -363,7 +320,7 @@ public void testIgnoreMissing() throws Exception { public void testAppendingToTheSameField() { Map source = Collections.singletonMap("field", Arrays.asList("a", "b")); - IngestDocument originalIngestDocument = new IngestDocument("_index", "_type", "_id", null, null, null, source); + IngestDocument originalIngestDocument = new IngestDocument("_index", "_id", null, null, null, source); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); TestProcessor testProcessor = new TestProcessor(id -> id.appendFieldValue("field", "a")); ForEachProcessor processor = new ForEachProcessor("_tag", null, "field", testProcessor, true); @@ -375,7 +332,7 @@ public void testAppendingToTheSameField() { public void testRemovingFromTheSameField() { Map source = Collections.singletonMap("field", Arrays.asList("a", "b")); - IngestDocument originalIngestDocument = new IngestDocument("_index", "_id", "_type", null, null, null, source); + IngestDocument originalIngestDocument = new IngestDocument("_index", "_id", null, null, null, source); IngestDocument ingestDocument = new IngestDocument(originalIngestDocument); TestProcessor testProcessor = new TestProcessor(id -> id.removeField("field.0")); ForEachProcessor processor = new ForEachProcessor("_tag", null, "field", testProcessor, true); diff --git a/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java b/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java index 2ef5d8da000b1..e88c77b8e33f4 100644 --- a/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java +++ b/modules/ingest-geoip/src/internalClusterTest/java/org/opensearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java @@ -167,7 +167,7 @@ public void testLazyLoading() throws IOException { internalCluster().getInstance(IngestService.class, ingestNode); // the geo-IP database should not be loaded yet as we have no indexed any documents using a pipeline that has a geo-IP processor assertDatabaseLoadStatus(ingestNode, false); - final IndexRequest indexRequest = new IndexRequest("index", "_doc"); + final IndexRequest indexRequest = new IndexRequest("index"); indexRequest.setPipeline("geoip"); indexRequest.source(Collections.singletonMap("ip", "1.1.1.1")); final IndexResponse indexResponse = client().index(indexRequest).actionGet(); diff --git a/modules/ingest-geoip/src/test/java/org/opensearch/ingest/geoip/GeoIpProcessorFactoryTests.java b/modules/ingest-geoip/src/test/java/org/opensearch/ingest/geoip/GeoIpProcessorFactoryTests.java index 15ca93e0fbae4..cda2f5692b0db 100644 --- a/modules/ingest-geoip/src/test/java/org/opensearch/ingest/geoip/GeoIpProcessorFactoryTests.java +++ b/modules/ingest-geoip/src/test/java/org/opensearch/ingest/geoip/GeoIpProcessorFactoryTests.java @@ -286,7 +286,7 @@ public void testLazyLoading() throws Exception { } final Map field = Collections.singletonMap("_field", "1.1.1.1"); - final IngestDocument document = new IngestDocument("index", "type", "id", "routing", 1L, VersionType.EXTERNAL, field); + final IngestDocument document = new IngestDocument("index", "id", "routing", 1L, VersionType.EXTERNAL, field); Map config = new HashMap<>(); config.put("field", "_field"); @@ -343,7 +343,7 @@ public void testLoadingCustomDatabase() throws IOException { } final Map field = Collections.singletonMap("_field", "1.1.1.1"); - final IngestDocument document = new IngestDocument("index", "type", "id", "routing", 1L, VersionType.EXTERNAL, field); + final IngestDocument document = new IngestDocument("index", "id", "routing", 1L, VersionType.EXTERNAL, field); Map config = new HashMap<>(); config.put("field", "_field"); diff --git a/modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/15_update.yml b/modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/15_update.yml index fd5c89b490d39..cb118ed9d562f 100644 --- a/modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/15_update.yml +++ b/modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/15_update.yml @@ -21,7 +21,6 @@ - match: { _index: test_1 } - match: { _id: "1" } - - match: { _type: _doc } - match: { _version: 2 } - do: @@ -43,7 +42,6 @@ - match: { _index: test_1 } - match: { _id: "1" } - - match: { _type: _doc } - match: { _version: 3 } - do: @@ -65,7 +63,6 @@ - match: { _index: test_1 } - match: { _id: "1" } - - match: { _type: _doc } - match: { _version: 4 } - do: @@ -89,7 +86,6 @@ - match: { _index: test_1 } - match: { _id: "1" } - - match: { _type: _doc } - match: { _version: 5 } - do: diff --git a/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml b/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml index f1851d9c35757..21843dad1d177 100644 --- a/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml +++ b/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/10_basic.yml @@ -19,7 +19,6 @@ setup: - do: index: index: test - type: _doc id: 1 body: a_field: "quick brown fox jump lazy dog" @@ -28,7 +27,6 @@ setup: - do: index: index: test - type: _doc id: 2 body: a_field: "xylophone xylophone xylophone" diff --git a/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/20_highlighting.yml b/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/20_highlighting.yml index 15778393959e5..58441abac8f88 100644 --- a/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/20_highlighting.yml +++ b/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/search-as-you-type/20_highlighting.yml @@ -22,7 +22,6 @@ setup: - do: index: index: test - type: _doc id: 1 body: a_field: "quick brown fox jump lazy dog" diff --git a/modules/reindex/src/internalClusterTest/java/org/opensearch/client/documentation/ReindexDocumentationIT.java b/modules/reindex/src/internalClusterTest/java/org/opensearch/client/documentation/ReindexDocumentationIT.java index b19de5150dfe8..827afdeb7ad86 100644 --- a/modules/reindex/src/internalClusterTest/java/org/opensearch/client/documentation/ReindexDocumentationIT.java +++ b/modules/reindex/src/internalClusterTest/java/org/opensearch/client/documentation/ReindexDocumentationIT.java @@ -311,7 +311,7 @@ private ReindexRequestBuilder reindexAndPartiallyBlock() throws Exception { assertThat(ALLOWED_OPERATIONS.drainPermits(), equalTo(0)); ReindexRequestBuilder builder = new ReindexRequestBuilder(client, ReindexAction.INSTANCE).source(INDEX_NAME) - .destination("target_index", "_doc"); + .destination("target_index"); // Scroll by 1 so that cancellation is easier to control builder.source().setSize(1); diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java index 82ebc009ca9d3..9c2e44f580628 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -341,15 +341,7 @@ public void testBulkResponseSetsLotsOfStatus() throws Exception { } final int seqNo = randomInt(20); final int primaryTerm = randomIntBetween(1, 16); - final IndexResponse response = new IndexResponse( - shardId, - "type", - "id" + i, - seqNo, - primaryTerm, - randomInt(), - createdResponse - ); + final IndexResponse response = new IndexResponse(shardId, "id" + i, seqNo, primaryTerm, randomInt(), createdResponse); responses[i] = new BulkItemResponse(i, opType, response); } assertExactlyOnce(onSuccess -> new DummyAsyncBulkByScrollAction().onBulkResponse(new BulkResponse(responses, 0), onSuccess)); @@ -596,7 +588,7 @@ private void bulkRetryTestCase(boolean failWithRejection) throws Exception { DummyAsyncBulkByScrollAction action = new DummyActionWithoutBackoff(); BulkRequest request = new BulkRequest(); for (int i = 0; i < size + 1; i++) { - request.add(new IndexRequest("index", "type", "id" + i)); + request.add(new IndexRequest("index").id("id" + i)); } if (failWithRejection) { action.sendBulkRequest(request, Assert::fail); @@ -945,7 +937,6 @@ protected void IndexRequest index = (IndexRequest) item; response = new IndexResponse( shardId, - index.type(), index.id() == null ? "dummy_id" : index.id(), randomInt(20), randomIntBetween(1, 16), @@ -956,7 +947,6 @@ protected void UpdateRequest update = (UpdateRequest) item; response = new UpdateResponse( shardId, - update.type(), update.id(), randomNonNegativeLong(), randomIntBetween(1, Integer.MAX_VALUE), @@ -967,7 +957,6 @@ protected void DeleteRequest delete = (DeleteRequest) item; response = new DeleteResponse( shardId, - delete.type(), delete.id(), randomInt(20), randomIntBetween(1, 16), diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/CancelTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/CancelTests.java index f36041380642f..bd43f05225f65 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/CancelTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/CancelTests.java @@ -45,7 +45,6 @@ import org.opensearch.index.IndexModule; import org.opensearch.index.engine.Engine; import org.opensearch.index.engine.Engine.Operation.Origin; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.shard.IndexingOperationListener; import org.opensearch.index.shard.ShardId; @@ -116,7 +115,7 @@ private void testCancel( false, true, IntStream.range(0, numDocs) - .mapToObj(i -> client().prepareIndex(INDEX, MapperService.SINGLE_MAPPING_NAME, String.valueOf(i)).setSource("n", i)) + .mapToObj(i -> client().prepareIndex().setIndex(INDEX).setId(String.valueOf(i)).setSource("n", i)) .collect(Collectors.toList()) ); @@ -247,17 +246,12 @@ public static TaskInfo findTaskToCancel(String actionName, int workerCount) { } public void testReindexCancel() throws Exception { - testCancel( - ReindexAction.NAME, - reindex().source(INDEX).destination("dest", MapperService.SINGLE_MAPPING_NAME), - (response, total, modified) -> { - assertThat(response, matcher().created(modified).reasonCancelled(equalTo("by user request"))); + testCancel(ReindexAction.NAME, reindex().source(INDEX).destination("dest"), (response, total, modified) -> { + assertThat(response, matcher().created(modified).reasonCancelled(equalTo("by user request"))); - refresh("dest"); - assertHitCount(client().prepareSearch("dest").setSize(0).get(), modified); - }, - equalTo("reindex from [" + INDEX + "] to [dest][" + MapperService.SINGLE_MAPPING_NAME + "]") - ); + refresh("dest"); + assertHitCount(client().prepareSearch("dest").setSize(0).get(), modified); + }, equalTo("reindex from [" + INDEX + "] to [dest]")); } public void testUpdateByQueryCancel() throws Exception { @@ -294,16 +288,13 @@ public void testDeleteByQueryCancel() throws Exception { public void testReindexCancelWithWorkers() throws Exception { testCancel( ReindexAction.NAME, - reindex().source(INDEX) - .filter(QueryBuilders.matchAllQuery()) - .destination("dest", MapperService.SINGLE_MAPPING_NAME) - .setSlices(5), + reindex().source(INDEX).filter(QueryBuilders.matchAllQuery()).destination("dest").setSlices(5), (response, total, modified) -> { assertThat(response, matcher().created(modified).reasonCancelled(equalTo("by user request")).slices(hasSize(5))); refresh("dest"); assertHitCount(client().prepareSearch("dest").setSize(0).get(), modified); }, - equalTo("reindex from [" + INDEX + "] to [dest][" + MapperService.SINGLE_MAPPING_NAME + "]") + equalTo("reindex from [" + INDEX + "] to [dest]") ); } diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexBasicTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexBasicTests.java index 6940f8a70bdcb..652e4d4d34fd5 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexBasicTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexBasicTests.java @@ -59,23 +59,23 @@ public void testFiltering() throws Exception { assertHitCount(client().prepareSearch("source").setSize(0).get(), 4); // Copy all the docs - ReindexRequestBuilder copy = reindex().source("source").destination("dest", "type").refresh(true); + ReindexRequestBuilder copy = reindex().source("source").destination("dest").refresh(true); assertThat(copy.get(), matcher().created(4)); assertHitCount(client().prepareSearch("dest").setSize(0).get(), 4); // Now none of them createIndex("none"); - copy = reindex().source("source").destination("none", "type").filter(termQuery("foo", "no_match")).refresh(true); + copy = reindex().source("source").destination("none").filter(termQuery("foo", "no_match")).refresh(true); assertThat(copy.get(), matcher().created(0)); assertHitCount(client().prepareSearch("none").setSize(0).get(), 0); // Now half of them - copy = reindex().source("source").destination("dest_half", "type").filter(termQuery("foo", "a")).refresh(true); + copy = reindex().source("source").destination("dest_half").filter(termQuery("foo", "a")).refresh(true); assertThat(copy.get(), matcher().created(2)); assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), 2); // Limit with maxDocs - copy = reindex().source("source").destination("dest_size_one", "type").maxDocs(1).refresh(true); + copy = reindex().source("source").destination("dest_size_one").maxDocs(1).refresh(true); assertThat(copy.get(), matcher().created(1)); assertHitCount(client().prepareSearch("dest_size_one").setSize(0).get(), 1); } @@ -91,7 +91,7 @@ public void testCopyMany() throws Exception { assertHitCount(client().prepareSearch("source").setSize(0).get(), max); // Copy all the docs - ReindexRequestBuilder copy = reindex().source("source").destination("dest", "type").refresh(true); + ReindexRequestBuilder copy = reindex().source("source").destination("dest").refresh(true); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); assertThat(copy.get(), matcher().created(max).batches(max, 5)); @@ -99,7 +99,7 @@ public void testCopyMany() throws Exception { // Copy some of the docs int half = max / 2; - copy = reindex().source("source").destination("dest_half", "type").refresh(true); + copy = reindex().source("source").destination("dest_half").refresh(true); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); copy.maxDocs(half); @@ -121,7 +121,7 @@ public void testCopyManyWithSlices() throws Exception { int expectedSlices = expectedSliceStatuses(slices, "source"); // Copy all the docs - ReindexRequestBuilder copy = reindex().source("source").destination("dest", "type").refresh(true).setSlices(slices); + ReindexRequestBuilder copy = reindex().source("source").destination("dest").refresh(true).setSlices(slices); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); assertThat(copy.get(), matcher().created(max).batches(greaterThanOrEqualTo(max / 5)).slices(hasSize(expectedSlices))); @@ -129,7 +129,7 @@ public void testCopyManyWithSlices() throws Exception { // Copy some of the docs int half = max / 2; - copy = reindex().source("source").destination("dest_half", "type").refresh(true).setSlices(slices); + copy = reindex().source("source").destination("dest_half").refresh(true).setSlices(slices); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); copy.maxDocs(half); @@ -162,7 +162,7 @@ public void testMultipleSources() throws Exception { int expectedSlices = expectedSliceStatuses(slices, docs.keySet()); String[] sourceIndexNames = docs.keySet().toArray(new String[docs.size()]); - ReindexRequestBuilder request = reindex().source(sourceIndexNames).destination("dest", "type").refresh(true).setSlices(slices); + ReindexRequestBuilder request = reindex().source(sourceIndexNames).destination("dest").refresh(true).setSlices(slices); BulkByScrollResponse response = request.get(); assertThat(response, matcher().created(allDocs.size()).slices(hasSize(expectedSlices))); diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java index 710be8f2ee679..aa8221b045d3f 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/RestReindexActionTests.java @@ -38,7 +38,6 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; -import org.opensearch.rest.RestRequest.Method; import org.opensearch.test.rest.FakeRestRequest; import org.opensearch.test.rest.RestActionTestCase; import org.junit.Before; @@ -101,28 +100,4 @@ public void testSetScrollTimeout() throws IOException { assertEquals("10m", request.getScrollTime().toString()); } } - - /** - * test deprecation is logged if a type is used in the destination index request inside reindex - */ - public void testTypeInDestination() throws IOException { - FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry()).withMethod(Method.POST) - .withPath("/_reindex"); - XContentBuilder b = JsonXContent.contentBuilder().startObject(); - { - b.startObject("dest"); - { - b.field("type", (randomBoolean() ? "_doc" : randomAlphaOfLength(4))); - } - b.endObject(); - } - b.endObject(); - requestBuilder.withContent(new BytesArray(BytesReference.bytes(b).toBytesRef()), XContentType.JSON); - - // We're not actually testing anything to do with the client, but need to set this so it doesn't fail the test for being unset. - verifyingClient.setExecuteLocallyVerifier((arg1, arg2) -> null); - - dispatchRequest(requestBuilder.build()); - assertWarnings(ReindexRequest.TYPES_DEPRECATION_MESSAGE); - } } diff --git a/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/delete_by_query/10_basic.yml b/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/delete_by_query/10_basic.yml index 6d870b9e46fdd..7783bbd1f9476 100644 --- a/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/delete_by_query/10_basic.yml +++ b/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/delete_by_query/10_basic.yml @@ -203,7 +203,6 @@ - do: index: index: test - type: _doc id: 1 body: { "text": "test" } - do: @@ -212,7 +211,6 @@ - do: index: index: test - type: _doc id: 1 body: { "text": "test2" } diff --git a/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/update_by_query/10_basic.yml b/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/update_by_query/10_basic.yml index 199c026db6eb2..4df12b31a0bed 100644 --- a/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/update_by_query/10_basic.yml +++ b/modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/update_by_query/10_basic.yml @@ -162,7 +162,6 @@ - do: index: index: test - type: _doc id: 1 body: { "text": "test" } - do: @@ -171,7 +170,6 @@ - do: index: index: test - type: _doc id: 1 body: { "text": "test2" } diff --git a/qa/os/src/test/java/org/opensearch/packaging/util/ServerUtils.java b/qa/os/src/test/java/org/opensearch/packaging/util/ServerUtils.java index dcc6829eb4143..d92feec21daaf 100644 --- a/qa/os/src/test/java/org/opensearch/packaging/util/ServerUtils.java +++ b/qa/os/src/test/java/org/opensearch/packaging/util/ServerUtils.java @@ -198,12 +198,12 @@ public static void waitForOpenSearch(String status, String index, Installation i public static void runOpenSearchTests() throws Exception { makeRequest( - Request.Post("http://localhost:9200/library/book/1?refresh=true&pretty") + Request.Post("http://localhost:9200/library/_doc/1?refresh=true&pretty") .bodyString("{ \"title\": \"Book #1\", \"pages\": 123 }", ContentType.APPLICATION_JSON) ); makeRequest( - Request.Post("http://localhost:9200/library/book/2?refresh=true&pretty") + Request.Post("http://localhost:9200/library/_doc/2?refresh=true&pretty") .bodyString("{ \"title\": \"Book #2\", \"pages\": 456 }", ContentType.APPLICATION_JSON) ); diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java index 1c1e3de7eae7d..687fd1743c3d3 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/RecoveryIT.java @@ -48,9 +48,6 @@ import org.opensearch.common.xcontent.support.XContentMapValues; import org.opensearch.index.IndexSettings; import org.opensearch.rest.RestStatus; -import org.opensearch.rest.action.document.RestGetAction; -import org.opensearch.rest.action.document.RestIndexAction; -import org.opensearch.rest.action.document.RestUpdateAction; import org.opensearch.test.rest.yaml.ObjectPath; import org.hamcrest.Matcher; import org.hamcrest.Matchers; @@ -67,7 +64,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Predicate; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength; +import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength; import static org.opensearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING; import static org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING; import static org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY; @@ -124,7 +121,7 @@ private int indexDocs(String index, final int idStart, final int numDocs) throws for (int i = 0; i < numDocs; i++) { final int id = idStart + i; Request indexDoc = new Request("PUT", index + "/_doc/" + id); - indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}"); + indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiLettersOfLength(2) + "\"}"); client().performRequest(indexDoc); } return numDocs; diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/IngestDocumentMustacheIT.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/IngestDocumentMustacheIT.java index 5b2468b6304b1..83643f3217720 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/IngestDocumentMustacheIT.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/IngestDocumentMustacheIT.java @@ -46,7 +46,7 @@ public class IngestDocumentMustacheIT extends AbstractScriptTestCase { public void testAccessMetadataViaTemplate() { Map document = new HashMap<>(); document.put("foo", "bar"); - IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, document); + IngestDocument ingestDocument = new IngestDocument("index", "id", null, null, null, document); ingestDocument.setFieldValue(compile("field1"), ValueSource.wrap("1 {{foo}}", scriptService)); assertThat(ingestDocument.getFieldValue("field1", String.class), equalTo("1 bar")); @@ -61,7 +61,7 @@ public void testAccessMapMetadataViaTemplate() { innerObject.put("baz", "hello baz"); innerObject.put("qux", Collections.singletonMap("fubar", "hello qux and fubar")); document.put("foo", innerObject); - IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, document); + IngestDocument ingestDocument = new IngestDocument("index", "id", null, null, null, document); ingestDocument.setFieldValue(compile("field1"), ValueSource.wrap("1 {{foo.bar}} {{foo.baz}} {{foo.qux.fubar}}", scriptService)); assertThat(ingestDocument.getFieldValue("field1", String.class), equalTo("1 hello bar hello baz hello qux and fubar")); @@ -80,7 +80,7 @@ public void testAccessListMetadataViaTemplate() { list.add(value); list.add(null); document.put("list2", list); - IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, document); + IngestDocument ingestDocument = new IngestDocument("index", "id", null, null, null, document); ingestDocument.setFieldValue(compile("field1"), ValueSource.wrap("1 {{list1.0}} {{list2.0}}", scriptService)); assertThat(ingestDocument.getFieldValue("field1", String.class), equalTo("1 foo {field=value}")); } @@ -90,7 +90,7 @@ public void testAccessIngestMetadataViaTemplate() { Map ingestMap = new HashMap<>(); ingestMap.put("timestamp", "bogus_timestamp"); document.put("_ingest", ingestMap); - IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, document); + IngestDocument ingestDocument = new IngestDocument("index", "id", null, null, null, document); ingestDocument.setFieldValue(compile("ingest_timestamp"), ValueSource.wrap("{{_ingest.timestamp}} and {{_source._ingest.timestamp}}", scriptService)); assertThat(ingestDocument.getFieldValue("ingest_timestamp", String.class), diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/ValueSourceMustacheIT.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/ValueSourceMustacheIT.java index 83641cca6156a..2804c73032f1b 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/ValueSourceMustacheIT.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/opensearch/ingest/ValueSourceMustacheIT.java @@ -77,7 +77,7 @@ public void testValueSourceWithTemplates() { } public void testAccessSourceViaTemplate() { - IngestDocument ingestDocument = new IngestDocument("marvel", "type", "id", null, null, null, new HashMap<>()); + IngestDocument ingestDocument = new IngestDocument("marvel", "id", null, null, null, new HashMap<>()); assertThat(ingestDocument.hasField("marvel"), is(false)); ingestDocument.setFieldValue(compile("{{_index}}"), ValueSource.wrap("{{_index}}", scriptService)); assertThat(ingestDocument.getFieldValue("marvel", String.class), equalTo("marvel")); diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yml index 0235a346ad3d7..e6a2a3d52e116 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yml @@ -295,7 +295,6 @@ "docs": [ { "_index": "index", - "_type": "type", "_id": "id", "_source": { "foo": "bar" diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml index 18929c47a4027..5eedae174eaa9 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/30_update_by_query_with_ingest.yml @@ -18,7 +18,6 @@ - do: index: index: twitter - type: _doc id: 1 body: { "user": "foobar" } - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json index 37f3cc9f9f82b..b4865403331b0 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/index.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/index.json @@ -35,53 +35,6 @@ "description":"The name of the index" } } - }, - { - "path":"/{index}/{type}", - "methods":[ - "POST" - ], - "parts":{ - "index":{ - "type":"string", - "description":"The name of the index" - }, - "type":{ - "type":"string", - "description":"The type of the document", - "deprecated":true - } - }, - "deprecated":{ - "version":"7.0.0", - "description":"Specifying types in urls has been deprecated" - } - }, - { - "path":"/{index}/{type}/{id}", - "methods":[ - "PUT", - "POST" - ], - "parts":{ - "id":{ - "type":"string", - "description":"Document ID" - }, - "index":{ - "type":"string", - "description":"The name of the index" - }, - "type":{ - "type":"string", - "description":"The type of the document", - "deprecated":true - } - }, - "deprecated":{ - "version":"7.0.0", - "description":"Specifying types in urls has been deprecated" - } } ] }, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml deleted file mode 100644 index 86d0d4b59e06b..0000000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -"External version": - - - do: - catch: bad_request - create: - index: test - id: 1 - body: { foo: bar } - version_type: external - version: 0 - - - match: { status: 400 } - - match: { error.type: action_request_validation_exception } - - match: { error.reason: "Validation Failed: 1: create operations only support internal versioning. use index instead;" } - - - do: - catch: bad_request - create: - index: test - id: 2 - body: { foo: bar } - version_type: external - version: 5 - - - match: { status: 400 } - - match: { error.type: action_request_validation_exception } - - match: { error.reason: "Validation Failed: 1: create operations only support internal versioning. use index instead;" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/11_shard_header.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/11_shard_header.yml index 3fc10bc8db12d..6a2f852b221c2 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/11_shard_header.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/11_shard_header.yml @@ -29,7 +29,6 @@ id: 1 - match: { _index: foobar } - - match: { _type: _doc } - match: { _id: "1"} - match: { _version: 2} - match: { _shards.total: 1} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/10_doc.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/10_doc.yml index 2ee5a77dc7df5..4cb6710cc161c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/update/10_doc.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/10_doc.yml @@ -20,7 +20,6 @@ one: 3 - match: { _index: test_1 } - - match: { _type: _doc } - match: { _id: "1" } - match: { _version: 2 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/11_shard_header.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/11_shard_header.yml index 41dba3551e64c..ffcb72027b33d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/update/11_shard_header.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/11_shard_header.yml @@ -32,7 +32,6 @@ foo: baz - match: { _index: foobar } - - match: { _type: _doc } - match: { _id: "1"} - match: { _version: 2} - match: { _shards.total: 1} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/13_legacy_doc.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/13_legacy_doc.yml index 08f3457400d4f..a97c68ba6ee3f 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/update/13_legacy_doc.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/13_legacy_doc.yml @@ -21,7 +21,6 @@ one: 3 - match: { _index: test_1 } - - match: { _type: _doc } - match: { _id: "1" } - match: { _version: 2 } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/IndicesRequestIT.java b/server/src/internalClusterTest/java/org/opensearch/action/IndicesRequestIT.java index ee4d4d76b6061..eeee000fa9c2d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/IndicesRequestIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/IndicesRequestIT.java @@ -234,11 +234,7 @@ public void testIndex() { String[] indexShardActions = new String[] { BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]" }; interceptTransportActions(indexShardActions); - IndexRequest indexRequest = new IndexRequest(randomIndexOrAlias(), "type", "id").source( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + IndexRequest indexRequest = new IndexRequest(randomIndexOrAlias()).id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); internalCluster().coordOnlyNodeClient().index(indexRequest).actionGet(); clearInterceptedActions(); @@ -249,7 +245,7 @@ public void testDelete() { String[] deleteShardActions = new String[] { BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]" }; interceptTransportActions(deleteShardActions); - DeleteRequest deleteRequest = new DeleteRequest(randomIndexOrAlias(), "type", "id"); + DeleteRequest deleteRequest = new DeleteRequest(randomIndexOrAlias()).id("id"); internalCluster().coordOnlyNodeClient().delete(deleteRequest).actionGet(); clearInterceptedActions(); @@ -263,7 +259,7 @@ public void testUpdate() { String indexOrAlias = randomIndexOrAlias(); client().prepareIndex(indexOrAlias, "type", "id").setSource("field", "value").get(); - UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1"); + UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1"); UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet(); assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); @@ -277,7 +273,7 @@ public void testUpdateUpsert() { interceptTransportActions(updateShardActions); String indexOrAlias = randomIndexOrAlias(); - UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").upsert(Requests.INDEX_CONTENT_TYPE, "field", "value") + UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "id").upsert(Requests.INDEX_CONTENT_TYPE, "field", "value") .doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1"); UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet(); assertEquals(DocWriteResponse.Result.CREATED, updateResponse.getResult()); @@ -293,7 +289,7 @@ public void testUpdateDelete() { String indexOrAlias = randomIndexOrAlias(); client().prepareIndex(indexOrAlias, "type", "id").setSource("field", "value").get(); - UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "type", "id").script( + UpdateRequest updateRequest = new UpdateRequest(indexOrAlias, "id").script( new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx.op='delete'", Collections.emptyMap()) ); UpdateResponse updateResponse = internalCluster().coordOnlyNodeClient().update(updateRequest).actionGet(); @@ -312,19 +308,19 @@ public void testBulk() { int numIndexRequests = iterations(1, 10); for (int i = 0; i < numIndexRequests; i++) { String indexOrAlias = randomIndexOrAlias(); - bulkRequest.add(new IndexRequest(indexOrAlias, "type", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value")); + bulkRequest.add(new IndexRequest(indexOrAlias).id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value")); indices.add(indexOrAlias); } int numDeleteRequests = iterations(1, 10); for (int i = 0; i < numDeleteRequests; i++) { String indexOrAlias = randomIndexOrAlias(); - bulkRequest.add(new DeleteRequest(indexOrAlias, "type", "id")); + bulkRequest.add(new DeleteRequest(indexOrAlias).id("id")); indices.add(indexOrAlias); } int numUpdateRequests = iterations(1, 10); for (int i = 0; i < numUpdateRequests; i++) { String indexOrAlias = randomIndexOrAlias(); - bulkRequest.add(new UpdateRequest(indexOrAlias, "type", "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1")); + bulkRequest.add(new UpdateRequest(indexOrAlias, "id").doc(Requests.INDEX_CONTENT_TYPE, "field1", "value1")); indices.add(indexOrAlias); } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/ListenerActionIT.java b/server/src/internalClusterTest/java/org/opensearch/action/ListenerActionIT.java index a0ddf68355a63..1512fa4934ca1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/ListenerActionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/ListenerActionIT.java @@ -48,7 +48,7 @@ public void testThreadedListeners() throws Throwable { final AtomicReference threadName = new AtomicReference<>(); Client client = client(); - IndexRequest request = new IndexRequest("test", "type", "1"); + IndexRequest request = new IndexRequest("test").id("1"); if (randomBoolean()) { // set the source, without it, we will have a verification failure request.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1"); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java index a53c28d170a93..a1ddc4a27a1f9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java @@ -240,10 +240,8 @@ public void testShrinkIndexPrimaryTerm() throws Exception { final String s = Integer.toString(id); final int hash = Math.floorMod(Murmur3HashFunction.hash(s), numberOfShards); if (hash == shardId) { - final IndexRequest request = new IndexRequest("source", "type", s).source( - "{ \"f\": \"" + s + "\"}", - XContentType.JSON - ); + final IndexRequest request = new IndexRequest("source").id(s) + .source("{ \"f\": \"" + s + "\"}", XContentType.JSON); client().index(request).get(); break; } else { diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/SplitIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/SplitIndexIT.java index e39262d427f70..14d337c34daa5 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/SplitIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/SplitIndexIT.java @@ -345,10 +345,8 @@ public void testSplitIndexPrimaryTerm() throws Exception { final String s = Integer.toString(id); final int hash = Math.floorMod(Murmur3HashFunction.hash(s), numberOfShards); if (hash == shardId) { - final IndexRequest request = new IndexRequest("source", "type", s).source( - "{ \"f\": \"" + s + "\"}", - XContentType.JSON - ); + final IndexRequest request = new IndexRequest("source").id(s) + .source("{ \"f\": \"" + s + "\"}", XContentType.JSON); client().index(request).get(); break; } else { diff --git a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java index a7adcdf4a8653..ab934170b594a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkIntegrationIT.java @@ -116,7 +116,7 @@ public void testBulkWithWriteIndexAndRouting() { .setSettings(twoShardsSettings) .get(); - IndexRequest indexRequestWithAlias = new IndexRequest("alias1", "type", "id"); + IndexRequest indexRequestWithAlias = new IndexRequest("alias1").id("id"); if (randomBoolean()) { indexRequestWithAlias.routing("1"); } @@ -138,7 +138,7 @@ public void testBulkWithWriteIndexAndRouting() { // allowing the auto-generated timestamp to externally be set would allow making the index inconsistent with duplicate docs public void testExternallySetAutoGeneratedTimestamp() { - IndexRequest indexRequest = new IndexRequest("index1", "_doc").source(Collections.singletonMap("foo", "baz")); + IndexRequest indexRequest = new IndexRequest("index1").source(Collections.singletonMap("foo", "baz")); indexRequest.process(Version.CURRENT, null, null); // sets the timestamp if (randomBoolean()) { indexRequest.id("test"); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkProcessorIT.java b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkProcessorIT.java index 5f7c2ecd718a6..850034bc631b1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkProcessorIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkProcessorIT.java @@ -248,17 +248,14 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception if (randomBoolean()) { testDocs++; processor.add( - new IndexRequest("test", "test", Integer.toString(testDocs)).source(Requests.INDEX_CONTENT_TYPE, "field", "value") + new IndexRequest("test").id(Integer.toString(testDocs)).source(Requests.INDEX_CONTENT_TYPE, "field", "value") ); multiGetRequestBuilder.add("test", Integer.toString(testDocs)); } else { testReadOnlyDocs++; processor.add( - new IndexRequest("test-ro", "test", Integer.toString(testReadOnlyDocs)).source( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ) + new IndexRequest("test-ro").id(Integer.toString(testReadOnlyDocs)) + .source(Requests.INDEX_CONTENT_TYPE, "field", "value") ); } } @@ -297,11 +294,8 @@ private static MultiGetRequestBuilder indexDocs(Client client, BulkProcessor pro MultiGetRequestBuilder multiGetRequestBuilder = client.prepareMultiGet(); for (int i = 1; i <= numDocs; i++) { processor.add( - new IndexRequest("test", "test", Integer.toString(i)).source( - Requests.INDEX_CONTENT_TYPE, - "field", - randomRealisticUnicodeOfLengthBetween(1, 30) - ) + new IndexRequest("test").id(Integer.toString(i)) + .source(Requests.INDEX_CONTENT_TYPE, "field", randomRealisticUnicodeOfLengthBetween(1, 30)) ); multiGetRequestBuilder.add("test", Integer.toString(i)); } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java index b9bbb70759163..f2b83fc92cc63 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/bulk/BulkWithUpdatesIT.java @@ -656,21 +656,21 @@ public void testThatInvalidIndexNamesShouldNotBreakCompleteBulkRequest() { // issue 6630 public void testThatFailedUpdateRequestReturnsCorrectType() throws Exception { BulkResponse indexBulkItemResponse = client().prepareBulk() - .add(new IndexRequest("test", "type", "3").source("{ \"title\" : \"Great Title of doc 3\" }", XContentType.JSON)) - .add(new IndexRequest("test", "type", "4").source("{ \"title\" : \"Great Title of doc 4\" }", XContentType.JSON)) - .add(new IndexRequest("test", "type", "5").source("{ \"title\" : \"Great Title of doc 5\" }", XContentType.JSON)) - .add(new IndexRequest("test", "type", "6").source("{ \"title\" : \"Great Title of doc 6\" }", XContentType.JSON)) + .add(new IndexRequest("test").id("3").source("{ \"title\" : \"Great Title of doc 3\" }", XContentType.JSON)) + .add(new IndexRequest("test").id("4").source("{ \"title\" : \"Great Title of doc 4\" }", XContentType.JSON)) + .add(new IndexRequest("test").id("5").source("{ \"title\" : \"Great Title of doc 5\" }", XContentType.JSON)) + .add(new IndexRequest("test").id("6").source("{ \"title\" : \"Great Title of doc 6\" }", XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .get(); assertNoFailures(indexBulkItemResponse); BulkResponse bulkItemResponse = client().prepareBulk() - .add(new IndexRequest("test", "type", "1").source("{ \"title\" : \"Great Title of doc 1\" }", XContentType.JSON)) - .add(new IndexRequest("test", "type", "2").source("{ \"title\" : \"Great Title of doc 2\" }", XContentType.JSON)) - .add(new UpdateRequest("test", "type", "3").doc("{ \"date\" : \"2014-01-30T23:59:57\"}", XContentType.JSON)) - .add(new UpdateRequest("test", "type", "4").doc("{ \"date\" : \"2014-13-30T23:59:57\"}", XContentType.JSON)) - .add(new DeleteRequest("test", "type", "5")) - .add(new DeleteRequest("test", "type", "6")) + .add(new IndexRequest("test").id("1").source("{ \"title\" : \"Great Title of doc 1\" }", XContentType.JSON)) + .add(new IndexRequest("test").id("2").source("{ \"title\" : \"Great Title of doc 2\" }", XContentType.JSON)) + .add(new UpdateRequest("test", "3").doc("{ \"date\" : \"2014-01-30T23:59:57\"}", XContentType.JSON)) + .add(new UpdateRequest("test", "4").doc("{ \"date\" : \"2014-13-30T23:59:57\"}", XContentType.JSON)) + .add(new DeleteRequest("test", "5")) + .add(new DeleteRequest("test", "6")) .get(); assertNoFailures(indexBulkItemResponse); @@ -691,11 +691,11 @@ private static String indexOrAlias() { public void testThatMissingIndexDoesNotAbortFullBulkRequest() throws Exception { createIndex("bulkindex1", "bulkindex2"); BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")) - .add(new IndexRequest("bulkindex2", "index2_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) - .add(new IndexRequest("bulkindex2", "index2_type").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) - .add(new UpdateRequest("bulkindex2", "index2_type", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")) - .add(new DeleteRequest("bulkindex2", "index2_type", "3")) + bulkRequest.add(new IndexRequest("bulkindex1").id("1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")) + .add(new IndexRequest("bulkindex2").id("1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) + .add(new IndexRequest("bulkindex2").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) + .add(new UpdateRequest("bulkindex2", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")) + .add(new DeleteRequest("bulkindex2", "3")) .setRefreshPolicy(RefreshPolicy.IMMEDIATE); client().bulk(bulkRequest).get(); @@ -705,11 +705,11 @@ public void testThatMissingIndexDoesNotAbortFullBulkRequest() throws Exception { assertBusy(() -> assertAcked(client().admin().indices().prepareClose("bulkindex2"))); BulkRequest bulkRequest2 = new BulkRequest(); - bulkRequest2.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")) - .add(new IndexRequest("bulkindex2", "index2_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) - .add(new IndexRequest("bulkindex2", "index2_type").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) - .add(new UpdateRequest("bulkindex2", "index2_type", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")) - .add(new DeleteRequest("bulkindex2", "index2_type", "3")) + bulkRequest2.add(new IndexRequest("bulkindex1").id("1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")) + .add(new IndexRequest("bulkindex2").id("1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) + .add(new IndexRequest("bulkindex2").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")) + .add(new UpdateRequest("bulkindex2", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")) + .add(new DeleteRequest("bulkindex2", "3")) .setRefreshPolicy(RefreshPolicy.IMMEDIATE); BulkResponse bulkResponse = client().bulk(bulkRequest2).get(); @@ -725,9 +725,9 @@ public void testFailedRequestsOnClosedIndex() throws Exception { assertBusy(() -> assertAcked(client().admin().indices().prepareClose("bulkindex1"))); BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE); - bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")) - .add(new UpdateRequest("bulkindex1", "index1_type", "1").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")) - .add(new DeleteRequest("bulkindex1", "index1_type", "1")); + bulkRequest.add(new IndexRequest("bulkindex1").id("1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")) + .add(new UpdateRequest("bulkindex1", "1").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")) + .add(new DeleteRequest("bulkindex1", "1")); BulkResponse bulkResponse = client().bulk(bulkRequest).get(); assertThat(bulkResponse.hasFailures(), is(true)); diff --git a/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java b/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java index fa2ebe3fa2108..541fe495ee8e8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java @@ -117,7 +117,7 @@ public void testAliases() throws Exception { logger.info("--> indexing against [alias1], should fail now"); IllegalArgumentException exception = expectThrows( IllegalArgumentException.class, - () -> client().index(indexRequest("alias1").type("type1").id("1").source(source("2", "test"), XContentType.JSON)).actionGet() + () -> client().index(indexRequest("alias1").id("1").source(source("2", "test"), XContentType.JSON)).actionGet() ); assertThat( exception.getMessage(), @@ -134,9 +134,8 @@ public void testAliases() throws Exception { }); logger.info("--> indexing against [alias1], should work now"); - IndexResponse indexResponse = client().index( - indexRequest("alias1").type("type1").id("1").source(source("1", "test"), XContentType.JSON) - ).actionGet(); + IndexResponse indexResponse = client().index(indexRequest("alias1").id("1").source(source("1", "test"), XContentType.JSON)) + .actionGet(); assertThat(indexResponse.getIndex(), equalTo("test")); logger.info("--> creating index [test_x]"); @@ -152,7 +151,7 @@ public void testAliases() throws Exception { logger.info("--> indexing against [alias1], should fail now"); exception = expectThrows( IllegalArgumentException.class, - () -> client().index(indexRequest("alias1").type("type1").id("1").source(source("2", "test"), XContentType.JSON)).actionGet() + () -> client().index(indexRequest("alias1").id("1").source(source("2", "test"), XContentType.JSON)).actionGet() ); assertThat( exception.getMessage(), @@ -164,10 +163,7 @@ public void testAliases() throws Exception { ); logger.info("--> deleting against [alias1], should fail now"); - exception = expectThrows( - IllegalArgumentException.class, - () -> client().delete(deleteRequest("alias1").type("type1").id("1")).actionGet() - ); + exception = expectThrows(IllegalArgumentException.class, () -> client().delete(deleteRequest("alias1").id("1")).actionGet()); assertThat( exception.getMessage(), equalTo( @@ -183,8 +179,7 @@ public void testAliases() throws Exception { }); logger.info("--> indexing against [alias1], should work now"); - indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"), XContentType.JSON)) - .actionGet(); + indexResponse = client().index(indexRequest("alias1").id("1").source(source("1", "test"), XContentType.JSON)).actionGet(); assertThat(indexResponse.getIndex(), equalTo("test")); assertAliasesVersionIncreases("test_x", () -> { @@ -193,12 +188,11 @@ public void testAliases() throws Exception { }); logger.info("--> indexing against [alias1], should work now"); - indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"), XContentType.JSON)) - .actionGet(); + indexResponse = client().index(indexRequest("alias1").id("1").source(source("1", "test"), XContentType.JSON)).actionGet(); assertThat(indexResponse.getIndex(), equalTo("test_x")); logger.info("--> deleting against [alias1], should fail now"); - DeleteResponse deleteResponse = client().delete(deleteRequest("alias1").type("type1").id("1")).actionGet(); + DeleteResponse deleteResponse = client().delete(deleteRequest("alias1").id("1")).actionGet(); assertThat(deleteResponse.getIndex(), equalTo("test_x")); assertAliasesVersionIncreases("test_x", () -> { @@ -207,8 +201,7 @@ public void testAliases() throws Exception { }); logger.info("--> indexing against [alias1], should work against [test_x]"); - indexResponse = client().index(indexRequest("alias1").type("type1").id("1").source(source("1", "test"), XContentType.JSON)) - .actionGet(); + indexResponse = client().index(indexRequest("alias1").id("1").source(source("1", "test"), XContentType.JSON)).actionGet(); assertThat(indexResponse.getIndex(), equalTo("test_x")); } @@ -290,28 +283,16 @@ public void testSearchingFilteringAliasesSingleIndex() throws Exception { logger.info("--> indexing against [test]"); client().index( - indexRequest("test").type("type1") - .id("1") - .source(source("1", "foo test"), XContentType.JSON) - .setRefreshPolicy(RefreshPolicy.IMMEDIATE) + indexRequest("test").id("1").source(source("1", "foo test"), XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("2") - .source(source("2", "bar test"), XContentType.JSON) - .setRefreshPolicy(RefreshPolicy.IMMEDIATE) + indexRequest("test").id("2").source(source("2", "bar test"), XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("3") - .source(source("3", "baz test"), XContentType.JSON) - .setRefreshPolicy(RefreshPolicy.IMMEDIATE) + indexRequest("test").id("3").source(source("3", "baz test"), XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("4") - .source(source("4", "something else"), XContentType.JSON) - .setRefreshPolicy(RefreshPolicy.IMMEDIATE) + indexRequest("test").id("4").source(source("4", "something else"), XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE) ).actionGet(); logger.info("--> checking single filtering alias search"); @@ -408,16 +389,16 @@ public void testSearchingFilteringAliasesTwoIndices() throws Exception { ); logger.info("--> indexing against [test1]"); - client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("1").source(source("1", "foo test"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("2").source(source("2", "bar test"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("3").source(source("3", "baz test"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("4").source(source("4", "something else"), XContentType.JSON)).get(); logger.info("--> indexing against [test2]"); - client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("5").source(source("5", "foo test"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("6").source(source("6", "bar test"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("7").source(source("7", "baz test"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("8").source(source("8", "something else"), XContentType.JSON)).get(); refresh(); @@ -524,17 +505,17 @@ public void testSearchingFilteringAliasesMultipleIndices() throws Exception { ); logger.info("--> indexing against [test1]"); - client().index(indexRequest("test1").type("type1").id("11").source(source("11", "foo test1"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("12").source(source("12", "bar test1"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("13").source(source("13", "baz test1"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("11").source(source("11", "foo test1"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("12").source(source("12", "bar test1"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("13").source(source("13", "baz test1"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("21").source(source("21", "foo test2"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("22").source(source("22", "bar test2"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("23").source(source("23", "baz test2"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("21").source(source("21", "foo test2"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("22").source(source("22", "bar test2"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("23").source(source("23", "baz test2"), XContentType.JSON)).get(); - client().index(indexRequest("test3").type("type1").id("31").source(source("31", "foo test3"), XContentType.JSON)).get(); - client().index(indexRequest("test3").type("type1").id("32").source(source("32", "bar test3"), XContentType.JSON)).get(); - client().index(indexRequest("test3").type("type1").id("33").source(source("33", "baz test3"), XContentType.JSON)).get(); + client().index(indexRequest("test3").id("31").source(source("31", "foo test3"), XContentType.JSON)).get(); + client().index(indexRequest("test3").id("32").source(source("32", "bar test3"), XContentType.JSON)).get(); + client().index(indexRequest("test3").id("33").source(source("33", "baz test3"), XContentType.JSON)).get(); refresh(); @@ -647,16 +628,16 @@ public void testDeletingByQueryFilteringAliases() throws Exception { ); logger.info("--> indexing against [test1]"); - client().index(indexRequest("test1").type("type1").id("1").source(source("1", "foo test"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("2").source(source("2", "bar test"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("3").source(source("3", "baz test"), XContentType.JSON)).get(); - client().index(indexRequest("test1").type("type1").id("4").source(source("4", "something else"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("1").source(source("1", "foo test"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("2").source(source("2", "bar test"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("3").source(source("3", "baz test"), XContentType.JSON)).get(); + client().index(indexRequest("test1").id("4").source(source("4", "something else"), XContentType.JSON)).get(); logger.info("--> indexing against [test2]"); - client().index(indexRequest("test2").type("type1").id("5").source(source("5", "foo test"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test"), XContentType.JSON)).get(); - client().index(indexRequest("test2").type("type1").id("8").source(source("8", "something else"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("5").source(source("5", "foo test"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("6").source(source("6", "bar test"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("7").source(source("7", "baz test"), XContentType.JSON)).get(); + client().index(indexRequest("test2").id("8").source(source("8", "something else"), XContentType.JSON)).get(); refresh(); @@ -744,7 +725,7 @@ public void testWaitForAliasCreationMultipleShards() throws Exception { for (int i = 0; i < 10; i++) { final String aliasName = "alias" + i; assertAliasesVersionIncreases("test", () -> assertAcked(admin().indices().prepareAliases().addAlias("test", aliasName))); - client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).get(); + client().index(indexRequest(aliasName).id("1").source(source("1", "test"), XContentType.JSON)).get(); } } @@ -765,7 +746,7 @@ public void testWaitForAliasCreationSingleShard() throws Exception { for (int i = 0; i < 10; i++) { final String aliasName = "alias" + i; assertAliasesVersionIncreases("test", () -> assertAcked(admin().indices().prepareAliases().addAlias("test", aliasName))); - client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).get(); + client().index(indexRequest(aliasName).id("1").source(source("1", "test"), XContentType.JSON)).get(); } } @@ -787,8 +768,7 @@ public void run() { "test", () -> assertAcked(admin().indices().prepareAliases().addAlias("test", aliasName)) ); - client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"), XContentType.JSON)) - .actionGet(); + client().index(indexRequest(aliasName).id("1").source(source("1", "test"), XContentType.JSON)).actionGet(); } }); } diff --git a/server/src/internalClusterTest/java/org/opensearch/broadcast/BroadcastActionsIT.java b/server/src/internalClusterTest/java/org/opensearch/broadcast/BroadcastActionsIT.java index c45155809a5ea..f9f99eb2662b0 100644 --- a/server/src/internalClusterTest/java/org/opensearch/broadcast/BroadcastActionsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/broadcast/BroadcastActionsIT.java @@ -40,7 +40,7 @@ import java.io.IOException; import static org.opensearch.client.Requests.indexRequest; -import static org.opensearch.index.query.QueryBuilders.termQuery; +import static org.opensearch.index.query.QueryBuilders.matchAllQuery; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -57,16 +57,16 @@ public void testBroadcastOperations() throws IOException { NumShards numShards = getNumShards("test"); logger.info("Running Cluster Health"); - client().index(indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet(); + client().index(indexRequest("test").id("1").source(source("1", "test"))).actionGet(); flush(); - client().index(indexRequest("test").type("type1").id("2").source(source("2", "test"))).actionGet(); + client().index(indexRequest("test").id("2").source(source("2", "test"))).actionGet(); refresh(); logger.info("Count"); // check count for (int i = 0; i < 5; i++) { // test successful - SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(termQuery("_type", "type1")).get(); + SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(matchAllQuery()).get(); assertThat(countResponse.getHits().getTotalHits().value, equalTo(2L)); assertThat(countResponse.getTotalShards(), equalTo(numShards.numPrimaries)); assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries)); diff --git a/server/src/internalClusterTest/java/org/opensearch/document/DocumentActionsIT.java b/server/src/internalClusterTest/java/org/opensearch/document/DocumentActionsIT.java index 92746a55eba65..4ca281fad157a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/document/DocumentActionsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/document/DocumentActionsIT.java @@ -90,7 +90,6 @@ public void testIndexActions() throws Exception { .get(); assertThat(indexResponse.getIndex(), equalTo(getConcreteIndexName())); assertThat(indexResponse.getId(), equalTo("1")); - assertThat(indexResponse.getType(), equalTo("type1")); logger.info("Refreshing"); RefreshResponse refreshResponse = refresh(); assertThat(refreshResponse.getSuccessfulShards(), equalTo(numShards.totalNumShards)); @@ -145,7 +144,6 @@ public void testIndexActions() throws Exception { DeleteResponse deleteResponse = client().prepareDelete("test", "type1", "1").execute().actionGet(); assertThat(deleteResponse.getIndex(), equalTo(getConcreteIndexName())); assertThat(deleteResponse.getId(), equalTo("1")); - assertThat(deleteResponse.getType(), equalTo("type1")); logger.info("Refreshing"); client().admin().indices().refresh(refreshRequest("test")).actionGet(); @@ -156,9 +154,9 @@ public void testIndexActions() throws Exception { } logger.info("Index [type1/1]"); - client().index(indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet(); + client().index(indexRequest("test").id("1").source(source("1", "test"))).actionGet(); logger.info("Index [type1/2]"); - client().index(indexRequest("test").type("type1").id("2").source(source("2", "test2"))).actionGet(); + client().index(indexRequest("test").id("2").source(source("2", "test2"))).actionGet(); logger.info("Flushing"); FlushResponse flushResult = client().admin().indices().prepareFlush("test").execute().actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/engine/InternalEngineMergeIT.java b/server/src/internalClusterTest/java/org/opensearch/index/engine/InternalEngineMergeIT.java index 47d7e974357d8..06ec4dc6d2812 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/engine/InternalEngineMergeIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/engine/InternalEngineMergeIT.java @@ -71,7 +71,6 @@ public void testMergesHappening() throws Exception { for (int j = 0; j < numDocs; ++j) { request.add( Requests.indexRequest("test") - .type("type1") .id(Long.toString(id++)) .source(jsonBuilder().startObject().field("l", randomLong()).endObject()) ); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/mapper/DynamicMappingIT.java b/server/src/internalClusterTest/java/org/opensearch/index/mapper/DynamicMappingIT.java index 96188b2c8b71d..cb01295ae734c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/mapper/DynamicMappingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/mapper/DynamicMappingIT.java @@ -93,10 +93,10 @@ public void testConflictingDynamicMappingsBulk() { assertTrue(bulkResponse.hasFailures()); } - private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String type, String field) throws IOException { + private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String field) throws IOException { ImmutableOpenMap indexMappings = mappings.getMappings().get("index"); assertNotNull(indexMappings); - MappingMetadata typeMappings = indexMappings.get(type); + MappingMetadata typeMappings = indexMappings.get(MapperService.SINGLE_MAPPING_NAME); assertNotNull(typeMappings); Map typeMappingsMap = typeMappings.getSourceAsMap(); Map properties = (Map) typeMappingsMap.get("properties"); @@ -134,9 +134,9 @@ public void run() { throw error.get(); } Thread.sleep(2000); - GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get(); + GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").get(); for (int i = 0; i < indexThreads.length; ++i) { - assertMappingsHaveField(mappings, "index", "type", "field" + i); + assertMappingsHaveField(mappings, "index", "field" + i); } for (int i = 0; i < indexThreads.length; ++i) { assertTrue(client().prepareGet("index", Integer.toString(i)).get().isExists()); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java index 5ad516a6514fb..0afe067afb686 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -130,7 +130,7 @@ public void testDynamicUpdates() throws Exception { for (int rec = 0; rec < recCount; rec++) { String type = "type"; String fieldName = "field_" + type + "_" + rec; - assertConcreteMappingsOnAll("test", type, fieldName); + assertConcreteMappingsOnAll("test", fieldName); } client().admin() @@ -377,7 +377,7 @@ public void testPutMappingsWithBlocks() { * Waits until mappings for the provided fields exist on all nodes. Note, this waits for the current * started shards and checks for concrete mappings. */ - private void assertConcreteMappingsOnAll(final String index, final String type, final String... fieldNames) { + private void assertConcreteMappingsOnAll(final String index, final String... fieldNames) { Set nodes = internalCluster().nodesInclude(index); assertThat(nodes, Matchers.not(Matchers.emptyIterable())); for (String node : nodes) { @@ -390,17 +390,17 @@ private void assertConcreteMappingsOnAll(final String index, final String type, assertNotNull("field " + fieldName + " doesn't exists on " + node, fieldType); } } - assertMappingOnMaster(index, type, fieldNames); + assertMappingOnMaster(index, fieldNames); } /** * Waits for the given mapping type to exists on the master node. */ - private void assertMappingOnMaster(final String index, final String type, final String... fieldNames) { - GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).setTypes(type).get(); + private void assertMappingOnMaster(final String index, final String... fieldNames) { + GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).get(); ImmutableOpenMap mappings = response.getMappings().get(index); assertThat(mappings, notNullValue()); - MappingMetadata mappingMetadata = mappings.get(type); + MappingMetadata mappingMetadata = mappings.get(MapperService.SINGLE_MAPPING_NAME); assertThat(mappingMetadata, notNullValue()); Map mappingSource = mappingMetadata.getSourceAsMap(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java index b4f5301681879..0772bc2965c4c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/memory/breaker/CircuitBreakerServiceIT.java @@ -403,7 +403,7 @@ public void testLimitsRequestSize() { int numRequests = inFlightRequestsLimit.bytesAsInt(); BulkRequest bulkRequest = new BulkRequest(); for (int i = 0; i < numRequests; i++) { - IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i)); + IndexRequest indexRequest = new IndexRequest("index").id(Integer.toString(i)); indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "num", i); bulkRequest.add(indexRequest); } diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java index 4c5d7bbcc7741..c4a4227c0bc9c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java @@ -839,7 +839,7 @@ public void testStrictAliasParsingInIndicesCreatedViaTemplates() throws Exceptio .get(); client().prepareIndex("a1", "test", "test").setSource("{}", XContentType.JSON).get(); - BulkResponse response = client().prepareBulk().add(new IndexRequest("a2", "test", "test").source("{}", XContentType.JSON)).get(); + BulkResponse response = client().prepareBulk().add(new IndexRequest("a2").id("test").source("{}", XContentType.JSON)).get(); assertThat(response.hasFailures(), is(false)); assertThat(response.getItems()[0].isFailed(), equalTo(false)); assertThat(response.getItems()[0].getIndex(), equalTo("a2")); @@ -856,7 +856,7 @@ public void testStrictAliasParsingInIndicesCreatedViaTemplates() throws Exceptio // an index that doesn't exist yet will succeed client().prepareIndex("b1", "test", "test").setSource("{}", XContentType.JSON).get(); - response = client().prepareBulk().add(new IndexRequest("b2", "test", "test").source("{}", XContentType.JSON)).get(); + response = client().prepareBulk().add(new IndexRequest("b2").id("test").source("{}", XContentType.JSON)).get(); assertThat(response.hasFailures(), is(false)); assertThat(response.getItems()[0].isFailed(), equalTo(false)); assertThat(response.getItems()[0].getId(), equalTo("test")); diff --git a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java index 20fd693868049..6317dd62418f3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/ingest/IngestClientIT.java @@ -138,7 +138,7 @@ public void testSimulate() throws Exception { source.put("foo", "bar"); source.put("fail", false); source.put("processed", true); - IngestDocument ingestDocument = new IngestDocument("index", "type", "id", null, null, null, source); + IngestDocument ingestDocument = new IngestDocument("index", "id", null, null, null, source); assertThat(simulateDocumentBaseResult.getIngestDocument().getSourceAndMetadata(), equalTo(ingestDocument.getSourceAndMetadata())); assertThat(simulateDocumentBaseResult.getFailure(), nullValue()); @@ -167,7 +167,7 @@ public void testBulkWithIngestFailures() throws Exception { int numRequests = scaledRandomIntBetween(32, 128); BulkRequest bulkRequest = new BulkRequest(); for (int i = 0; i < numRequests; i++) { - IndexRequest indexRequest = new IndexRequest("index", "type", Integer.toString(i)).setPipeline("_id"); + IndexRequest indexRequest = new IndexRequest("index").id(Integer.toString(i)).setPipeline("_id"); indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field", "value", "fail", i % 2 == 0); bulkRequest.add(indexRequest); } @@ -216,10 +216,10 @@ public void testBulkWithUpsert() throws Exception { client().admin().cluster().putPipeline(putPipelineRequest).get(); BulkRequest bulkRequest = new BulkRequest(); - IndexRequest indexRequest = new IndexRequest("index", "type", "1").setPipeline("_id"); + IndexRequest indexRequest = new IndexRequest("index").id("1").setPipeline("_id"); indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "val1"); bulkRequest.add(indexRequest); - UpdateRequest updateRequest = new UpdateRequest("index", "type", "2"); + UpdateRequest updateRequest = new UpdateRequest("index", "2"); updateRequest.doc("{}", Requests.INDEX_CONTENT_TYPE); updateRequest.upsert("{\"field1\":\"upserted_val\"}", XContentType.JSON).upsertRequest().setPipeline("_id"); bulkRequest.add(updateRequest); diff --git a/server/src/internalClusterTest/java/org/opensearch/recovery/SimpleRecoveryIT.java b/server/src/internalClusterTest/java/org/opensearch/recovery/SimpleRecoveryIT.java index 6dec99be51194..4ebb840c600d2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/recovery/SimpleRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/recovery/SimpleRecoveryIT.java @@ -67,12 +67,12 @@ public void testSimpleRecovery() throws Exception { NumShards numShards = getNumShards("test"); - client().index(indexRequest("test").type("type1").id("1").source(source("1", "test"), XContentType.JSON)).actionGet(); + client().index(indexRequest("test").id("1").source(source("1", "test"), XContentType.JSON)).actionGet(); FlushResponse flushResponse = client().admin().indices().flush(flushRequest("test")).actionGet(); assertThat(flushResponse.getTotalShards(), equalTo(numShards.totalNumShards)); assertThat(flushResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries)); assertThat(flushResponse.getFailedShards(), equalTo(0)); - client().index(indexRequest("test").type("type1").id("2").source(source("2", "test"), XContentType.JSON)).actionGet(); + client().index(indexRequest("test").id("2").source(source("2", "test"), XContentType.JSON)).actionGet(); RefreshResponse refreshResponse = client().admin().indices().refresh(refreshRequest("test")).actionGet(); assertThat(refreshResponse.getTotalShards(), equalTo(numShards.totalNumShards)); assertThat(refreshResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries)); diff --git a/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java index 81cf1094a2648..6e9498d177aaf 100644 --- a/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java @@ -467,7 +467,7 @@ public void testRequiredRoutingBulk() throws Exception { ensureGreen(); { BulkResponse bulkResponse = client().prepareBulk() - .add(Requests.indexRequest(indexOrAlias()).type("type1").id("1").source(Requests.INDEX_CONTENT_TYPE, "field", "value")) + .add(Requests.indexRequest(indexOrAlias()).id("1").source(Requests.INDEX_CONTENT_TYPE, "field", "value")) .execute() .actionGet(); assertThat(bulkResponse.getItems().length, equalTo(1)); @@ -484,13 +484,7 @@ public void testRequiredRoutingBulk() throws Exception { { BulkResponse bulkResponse = client().prepareBulk() - .add( - Requests.indexRequest(indexOrAlias()) - .type("type1") - .id("1") - .routing("0") - .source(Requests.INDEX_CONTENT_TYPE, "field", "value") - ) + .add(Requests.indexRequest(indexOrAlias()).id("1").routing("0").source(Requests.INDEX_CONTENT_TYPE, "field", "value")) .execute() .actionGet(); assertThat(bulkResponse.hasFailures(), equalTo(false)); @@ -498,7 +492,7 @@ public void testRequiredRoutingBulk() throws Exception { { BulkResponse bulkResponse = client().prepareBulk() - .add(new UpdateRequest(indexOrAlias(), "type1", "1").doc(Requests.INDEX_CONTENT_TYPE, "field", "value2")) + .add(new UpdateRequest(indexOrAlias(), "1").doc(Requests.INDEX_CONTENT_TYPE, "field", "value2")) .execute() .actionGet(); assertThat(bulkResponse.getItems().length, equalTo(1)); @@ -515,17 +509,14 @@ public void testRequiredRoutingBulk() throws Exception { { BulkResponse bulkResponse = client().prepareBulk() - .add(new UpdateRequest(indexOrAlias(), "type1", "1").doc(Requests.INDEX_CONTENT_TYPE, "field", "value2").routing("0")) + .add(new UpdateRequest(indexOrAlias(), "1").doc(Requests.INDEX_CONTENT_TYPE, "field", "value2").routing("0")) .execute() .actionGet(); assertThat(bulkResponse.hasFailures(), equalTo(false)); } { - BulkResponse bulkResponse = client().prepareBulk() - .add(Requests.deleteRequest(indexOrAlias()).type("type1").id("1")) - .execute() - .actionGet(); + BulkResponse bulkResponse = client().prepareBulk().add(Requests.deleteRequest(indexOrAlias()).id("1")).execute().actionGet(); assertThat(bulkResponse.getItems().length, equalTo(1)); assertThat(bulkResponse.hasFailures(), equalTo(true)); @@ -540,7 +531,7 @@ public void testRequiredRoutingBulk() throws Exception { { BulkResponse bulkResponse = client().prepareBulk() - .add(Requests.deleteRequest(indexOrAlias()).type("type1").id("1").routing("0")) + .add(Requests.deleteRequest(indexOrAlias()).id("1").routing("0")) .execute() .actionGet(); assertThat(bulkResponse.getItems().length, equalTo(1)); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportSearchFailuresIT.java b/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportSearchFailuresIT.java index b44e4be011475..7982d9f5781fc 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportSearchFailuresIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportSearchFailuresIT.java @@ -136,7 +136,7 @@ public void testFailedSearchWithWrongQuery() throws Exception { } private void index(Client client, String id, String nameValue, int age) throws IOException { - client.index(Requests.indexRequest("test").type("type").id(id).source(source(id, nameValue, age))).actionGet(); + client.index(Requests.indexRequest("test").id(id).source(source(id, nameValue, age))).actionGet(); } private XContentBuilder source(String id, String nameValue, int age) throws IOException { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java index 23ca51b830fe1..420121006a943 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java @@ -109,7 +109,7 @@ private Set prepareData(int numShards) throws Exception { } private void index(String id, String nameValue, int age) throws IOException { - client().index(Requests.indexRequest("test").type("type").id(id).source(source(id, nameValue, age))).actionGet(); + client().index(Requests.indexRequest("test").id(id).source(source(id, nameValue, age))).actionGet(); } private XContentBuilder source(String id, String nameValue, int age) throws IOException { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java index 082a8df529a0b..68bac89213c57 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java @@ -94,9 +94,8 @@ public void testPlugin() throws Exception { ) .get(); - client().index( - indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("test", "I am sam i am").endObject()) - ).actionGet(); + client().index(indexRequest("test").id("1").source(jsonBuilder().startObject().field("test", "I am sam i am").endObject())) + .actionGet(); client().admin().indices().prepareRefresh().get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java index 2c77e3d1d44e3..0f47877facaff 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java @@ -645,14 +645,10 @@ public void testExceptionThrownIfScaleLE0() throws Exception { ) ); client().index( - indexRequest("test").type("type1") - .id("1") - .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject()) + indexRequest("test").id("1").source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject()) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("2") - .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-28").endObject()) + indexRequest("test").id("2").source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-28").endObject()) ).actionGet(); refresh(); @@ -690,13 +686,11 @@ public void testParseDateMath() throws Exception { ) ); client().index( - indexRequest("test").type("type1") - .id("1") + indexRequest("test").id("1") .source(jsonBuilder().startObject().field("test", "value").field("num1", System.currentTimeMillis()).endObject()) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("2") + indexRequest("test").id("2") .source( jsonBuilder().startObject() .field("test", "value") @@ -749,24 +743,18 @@ public void testValueMissingLin() throws Exception { ); client().index( - indexRequest("test").type("type1") - .id("1") + indexRequest("test").id("1") .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").field("num2", "1.0").endObject()) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("2") - .source(jsonBuilder().startObject().field("test", "value").field("num2", "1.0").endObject()) + indexRequest("test").id("2").source(jsonBuilder().startObject().field("test", "value").field("num2", "1.0").endObject()) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("3") + indexRequest("test").id("3") .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-30").field("num2", "1.0").endObject()) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("4") - .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-30").endObject()) + indexRequest("test").id("4").source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-30").endObject()) ).actionGet(); refresh(); @@ -827,9 +815,7 @@ public void testDateWithoutOrigin() throws Exception { + "-" + String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth()); client().index( - indexRequest("test").type("type1") - .id("1") - .source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject()) + indexRequest("test").id("1").source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject()) ).actionGet(); docDate = dt.minusDays(2); docDateString = docDate.getYear() @@ -838,9 +824,7 @@ public void testDateWithoutOrigin() throws Exception { + "-" + String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth()); client().index( - indexRequest("test").type("type1") - .id("2") - .source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject()) + indexRequest("test").id("2").source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject()) ).actionGet(); docDate = dt.minusDays(3); docDateString = docDate.getYear() @@ -849,9 +833,7 @@ public void testDateWithoutOrigin() throws Exception { + "-" + String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth()); client().index( - indexRequest("test").type("type1") - .id("3") - .source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject()) + indexRequest("test").id("3").source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject()) ).actionGet(); refresh(); @@ -987,16 +969,15 @@ public void testParsingExceptionIfFieldDoesNotExist() throws Exception { ); int numDocs = 2; client().index( - indexRequest("test").type("type") - .source( - jsonBuilder().startObject() - .field("test", "value") - .startObject("geo") - .field("lat", 1) - .field("lon", 2) - .endObject() - .endObject() - ) + indexRequest("test").source( + jsonBuilder().startObject() + .field("test", "value") + .startObject("geo") + .field("lat", 1) + .field("lon", 2) + .endObject() + .endObject() + ) ).actionGet(); refresh(); List lonlat = new ArrayList<>(); @@ -1040,8 +1021,7 @@ public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception { ) ); client().index( - indexRequest("test").type("type") - .source(jsonBuilder().startObject().field("test", "value").field("num", Integer.toString(1)).endObject()) + indexRequest("test").source(jsonBuilder().startObject().field("test", "value").field("num", Integer.toString(1)).endObject()) ).actionGet(); refresh(); // so, we indexed a string field, but now we try to score a num field @@ -1079,9 +1059,8 @@ public void testNoQueryGiven() throws Exception { .endObject() ) ); - client().index( - indexRequest("test").type("type").source(jsonBuilder().startObject().field("test", "value").field("num", 1.0).endObject()) - ).actionGet(); + client().index(indexRequest("test").source(jsonBuilder().startObject().field("test", "value").field("num", 1.0).endObject())) + .actionGet(); refresh(); // so, we indexed a string field, but now we try to score a num field ActionFuture response = client().search( diff --git a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java index ca69c38d1fcda..af7633628dab1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java @@ -95,14 +95,10 @@ public void testPlugin() throws Exception { client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().get(); client().index( - indexRequest("test").type("type1") - .id("1") - .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-26").endObject()) + indexRequest("test").id("1").source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-26").endObject()) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("2") - .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject()) + indexRequest("test").id("2").source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject()) ).actionGet(); client().admin().indices().prepareRefresh().get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java b/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java index e250daa54a399..0a2ddb607ccc5 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java @@ -105,11 +105,9 @@ public void testSimpleMoreLikeThis() throws Exception { assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); logger.info("Indexing..."); - client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("text", "lucene").endObject())) + client().index(indexRequest("test").id("1").source(jsonBuilder().startObject().field("text", "lucene").endObject())).actionGet(); + client().index(indexRequest("test").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject())) .actionGet(); - client().index( - indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject()) - ).actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); logger.info("Running moreLikeThis"); @@ -140,11 +138,9 @@ public void testSimpleMoreLikeThisWithTypes() throws Exception { assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); logger.info("Indexing..."); - client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("text", "lucene").endObject())) + client().index(indexRequest("test").id("1").source(jsonBuilder().startObject().field("text", "lucene").endObject())).actionGet(); + client().index(indexRequest("test").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject())) .actionGet(); - client().index( - indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject()) - ).actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); logger.info("Running moreLikeThis"); @@ -177,14 +173,10 @@ public void testMoreLikeThisForZeroTokensInOneOfTheAnalyzedFields() throws Excep ensureGreen(); client().index( - indexRequest("test").type("type") - .id("1") - .source(jsonBuilder().startObject().field("myField", "and_foo").field("empty", "").endObject()) + indexRequest("test").id("1").source(jsonBuilder().startObject().field("myField", "and_foo").field("empty", "").endObject()) ).actionGet(); client().index( - indexRequest("test").type("type") - .id("2") - .source(jsonBuilder().startObject().field("myField", "and_foo").field("empty", "").endObject()) + indexRequest("test").id("2").source(jsonBuilder().startObject().field("myField", "and_foo").field("empty", "").endObject()) ).actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); @@ -206,13 +198,10 @@ public void testSimpleMoreLikeOnLongField() throws Exception { assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); logger.info("Indexing..."); - client().index( - indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("some_long", 1367484649580L).endObject()) - ).actionGet(); - client().index(indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())) - .actionGet(); - client().index(indexRequest("test").type("type1").id("3").source(jsonBuilder().startObject().field("some_long", -666).endObject())) + client().index(indexRequest("test").id("1").source(jsonBuilder().startObject().field("some_long", 1367484649580L).endObject())) .actionGet(); + client().index(indexRequest("test").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet(); + client().index(indexRequest("test").id("3").source(jsonBuilder().startObject().field("some_long", -666).endObject())).actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); @@ -251,18 +240,14 @@ public void testMoreLikeThisWithAliases() throws Exception { assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); logger.info("Indexing..."); - client().index( - indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("text", "lucene beta").endObject()) - ).actionGet(); - client().index( - indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject()) - ).actionGet(); - client().index( - indexRequest("test").type("type1").id("3").source(jsonBuilder().startObject().field("text", "opensearch beta").endObject()) - ).actionGet(); - client().index( - indexRequest("test").type("type1").id("4").source(jsonBuilder().startObject().field("text", "opensearch release").endObject()) - ).actionGet(); + client().index(indexRequest("test").id("1").source(jsonBuilder().startObject().field("text", "lucene beta").endObject())) + .actionGet(); + client().index(indexRequest("test").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject())) + .actionGet(); + client().index(indexRequest("test").id("3").source(jsonBuilder().startObject().field("text", "opensearch beta").endObject())) + .actionGet(); + client().index(indexRequest("test").id("4").source(jsonBuilder().startObject().field("text", "opensearch release").endObject())) + .actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); logger.info("Running moreLikeThis on index"); @@ -308,15 +293,12 @@ public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception { assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); - client().index( - indexRequest(indexName).type(typeName).id("1").source(jsonBuilder().startObject().field("text", "opensearch index").endObject()) - ).actionGet(); - client().index( - indexRequest(indexName).type(typeName).id("2").source(jsonBuilder().startObject().field("text", "lucene index").endObject()) - ).actionGet(); - client().index( - indexRequest(indexName).type(typeName).id("3").source(jsonBuilder().startObject().field("text", "opensearch index").endObject()) - ).actionGet(); + client().index(indexRequest(indexName).id("1").source(jsonBuilder().startObject().field("text", "opensearch index").endObject())) + .actionGet(); + client().index(indexRequest(indexName).id("2").source(jsonBuilder().startObject().field("text", "lucene index").endObject())) + .actionGet(); + client().index(indexRequest(indexName).id("3").source(jsonBuilder().startObject().field("text", "opensearch index").endObject())) + .actionGet(); refresh(indexName); SearchResponse response = client().prepareSearch() @@ -561,8 +543,7 @@ public void testSimpleMoreLikeInclude() throws Exception { logger.info("Indexing..."); client().index( - indexRequest("test").type("type1") - .id("1") + indexRequest("test").id("1") .source( jsonBuilder().startObject() .field("text", "Apache Lucene is a free/open source information retrieval software library") @@ -570,8 +551,7 @@ public void testSimpleMoreLikeInclude() throws Exception { ) ).actionGet(); client().index( - indexRequest("test").type("type1") - .id("2") + indexRequest("test").id("2") .source(jsonBuilder().startObject().field("text", "Lucene has been ported to other programming languages").endObject()) ).actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/update/UpdateIT.java b/server/src/internalClusterTest/java/org/opensearch/update/UpdateIT.java index 3799d3325dc97..8f0188c592527 100644 --- a/server/src/internalClusterTest/java/org/opensearch/update/UpdateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/update/UpdateIT.java @@ -326,7 +326,7 @@ public void testUpdate() throws Exception { DocumentMissingException.class, () -> client().prepareUpdate(indexOrAlias(), "type1", "1").setScript(fieldIncScript).execute().actionGet() ); - assertEquals("[type1][1]: document missing", ex.getMessage()); + assertEquals("[1]: document missing", ex.getMessage()); client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/versioning/ConcurrentSeqNoVersioningIT.java b/server/src/internalClusterTest/java/org/opensearch/versioning/ConcurrentSeqNoVersioningIT.java index c1dd439cce4aa..a14e1279c1051 100644 --- a/server/src/internalClusterTest/java/org/opensearch/versioning/ConcurrentSeqNoVersioningIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/versioning/ConcurrentSeqNoVersioningIT.java @@ -255,7 +255,8 @@ public void run() { version = version.previousTerm(); } - IndexRequest indexRequest = new IndexRequest("test", "type", partition.id).source("value", random.nextInt()) + IndexRequest indexRequest = new IndexRequest("test").id(partition.id) + .source("value", random.nextInt()) .setIfPrimaryTerm(version.primaryTerm) .setIfSeqNo(version.seqNo); Consumer historyResponse = partition.invoke(version); diff --git a/server/src/internalClusterTest/java/org/opensearch/versioning/SimpleVersioningIT.java b/server/src/internalClusterTest/java/org/opensearch/versioning/SimpleVersioningIT.java index 2be21d8531182..9cbcc19cb47eb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/versioning/SimpleVersioningIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/versioning/SimpleVersioningIT.java @@ -578,8 +578,6 @@ public String toString() { sb.append(deleteResponse.getIndex()); sb.append(" id="); sb.append(deleteResponse.getId()); - sb.append(" type="); - sb.append(deleteResponse.getType()); sb.append(" version="); sb.append(deleteResponse.getVersion()); sb.append(" found="); @@ -590,8 +588,6 @@ public String toString() { sb.append(indexResponse.getIndex()); sb.append(" id="); sb.append(indexResponse.getId()); - sb.append(" type="); - sb.append(indexResponse.getType()); sb.append(" version="); sb.append(indexResponse.getVersion()); sb.append(" created="); diff --git a/server/src/main/java/org/opensearch/action/DocWriteRequest.java b/server/src/main/java/org/opensearch/action/DocWriteRequest.java index 914a65bada542..11d645435c71c 100644 --- a/server/src/main/java/org/opensearch/action/DocWriteRequest.java +++ b/server/src/main/java/org/opensearch/action/DocWriteRequest.java @@ -71,18 +71,6 @@ public interface DocWriteRequest extends IndicesRequest, Accountable { */ String index(); - /** - * Set the type for this request - * @return the Request - */ - T type(String type); - - /** - * Get the type that this request operates on - * @return the type - */ - String type(); - /** * Get the id of the document for this request * @return the id diff --git a/server/src/main/java/org/opensearch/action/DocWriteResponse.java b/server/src/main/java/org/opensearch/action/DocWriteResponse.java index 9cec09b9d8b10..587f93ed09f52 100644 --- a/server/src/main/java/org/opensearch/action/DocWriteResponse.java +++ b/server/src/main/java/org/opensearch/action/DocWriteResponse.java @@ -31,6 +31,7 @@ package org.opensearch.action; +import org.opensearch.Version; import org.opensearch.action.support.WriteRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.action.support.WriteResponse; @@ -45,6 +46,7 @@ import org.opensearch.common.xcontent.XContentParser; import org.opensearch.index.Index; import org.opensearch.index.IndexSettings; +import org.opensearch.index.mapper.MapperService; import org.opensearch.index.seqno.SequenceNumbers; import org.opensearch.index.shard.ShardId; import org.opensearch.rest.RestStatus; @@ -66,7 +68,6 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr private static final String _SHARDS = "_shards"; private static final String _INDEX = "_index"; - private static final String _TYPE = "_type"; private static final String _ID = "_id"; private static final String _VERSION = "_version"; private static final String _SEQ_NO = "_seq_no"; @@ -127,16 +128,14 @@ public void writeTo(StreamOutput out) throws IOException { private final ShardId shardId; private final String id; - private final String type; private final long version; private final long seqNo; private final long primaryTerm; private boolean forcedRefresh; protected final Result result; - public DocWriteResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, Result result) { + public DocWriteResponse(ShardId shardId, String id, long seqNo, long primaryTerm, long version, Result result) { this.shardId = Objects.requireNonNull(shardId); - this.type = Objects.requireNonNull(type); this.id = Objects.requireNonNull(id); this.seqNo = seqNo; this.primaryTerm = primaryTerm; @@ -148,7 +147,10 @@ public DocWriteResponse(ShardId shardId, String type, String id, long seqNo, lon protected DocWriteResponse(ShardId shardId, StreamInput in) throws IOException { super(in); this.shardId = shardId; - type = in.readString(); + if (in.getVersion().before(Version.V_2_0_0)) { + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but received [" + type + "]"; + } id = in.readString(); version = in.readZLong(); seqNo = in.readZLong(); @@ -164,7 +166,10 @@ protected DocWriteResponse(ShardId shardId, StreamInput in) throws IOException { protected DocWriteResponse(StreamInput in) throws IOException { super(in); shardId = new ShardId(in); - type = in.readString(); + if (in.getVersion().before(Version.V_2_0_0)) { + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but received [" + type + "]"; + } id = in.readString(); version = in.readZLong(); seqNo = in.readZLong(); @@ -194,16 +199,6 @@ public ShardId getShardId() { return this.shardId; } - /** - * The type of the document changed. - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - public String getType() { - return this.type; - } - /** * The id of the document changed. */ @@ -270,7 +265,7 @@ public String getLocation(@Nullable String routing) { try { // encode the path components separately otherwise the path separators will be encoded encodedIndex = URLEncoder.encode(getIndex(), "UTF-8"); - encodedType = URLEncoder.encode(getType(), "UTF-8"); + encodedType = URLEncoder.encode(MapperService.SINGLE_MAPPING_NAME, "UTF-8"); encodedId = URLEncoder.encode(getId(), "UTF-8"); encodedRouting = routing == null ? null : URLEncoder.encode(routing, "UTF-8"); } catch (final UnsupportedEncodingException e) { @@ -308,7 +303,9 @@ public void writeTo(StreamOutput out) throws IOException { } private void writeWithoutShardId(StreamOutput out) throws IOException { - out.writeString(type); + if (out.getVersion().before(Version.V_2_0_0)) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + } out.writeString(id); out.writeZLong(version); out.writeZLong(seqNo); @@ -328,7 +325,6 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params) public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException { ReplicationResponse.ShardInfo shardInfo = getShardInfo(); builder.field(_INDEX, shardId.getIndexName()); - builder.field(_TYPE, type); builder.field(_ID, id).field(_VERSION, version).field(RESULT, getResult().getLowercase()); if (forcedRefresh) { builder.field(FORCED_REFRESH, true); @@ -359,8 +355,6 @@ protected static void parseInnerToXContent(XContentParser parser, Builder contex if (_INDEX.equals(currentFieldName)) { // index uuid and shard id are unknown and can't be parsed back for now. context.setShardId(new ShardId(new Index(parser.text(), IndexMetadata.INDEX_UUID_NA_VALUE), -1)); - } else if (_TYPE.equals(currentFieldName)) { - context.setType(parser.text()); } else if (_ID.equals(currentFieldName)) { context.setId(parser.text()); } else if (_VERSION.equals(currentFieldName)) { @@ -399,7 +393,6 @@ protected static void parseInnerToXContent(XContentParser parser, Builder contex public abstract static class Builder { protected ShardId shardId = null; - protected String type = null; protected String id = null; protected Long version = null; protected Result result = null; @@ -416,14 +409,6 @@ public void setShardId(ShardId shardId) { this.shardId = shardId; } - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - public String getId() { return id; } diff --git a/server/src/main/java/org/opensearch/action/bulk/BulkPrimaryExecutionContext.java b/server/src/main/java/org/opensearch/action/bulk/BulkPrimaryExecutionContext.java index 59627da5196e2..da8833fe49a29 100644 --- a/server/src/main/java/org/opensearch/action/bulk/BulkPrimaryExecutionContext.java +++ b/server/src/main/java/org/opensearch/action/bulk/BulkPrimaryExecutionContext.java @@ -268,7 +268,6 @@ public void markOperationAsExecuted(Engine.Result result) { Engine.IndexResult indexResult = (Engine.IndexResult) result; response = new IndexResponse( primary.shardId(), - requestToExecute.type(), requestToExecute.id(), result.getSeqNo(), result.getTerm(), @@ -279,7 +278,6 @@ public void markOperationAsExecuted(Engine.Result result) { Engine.DeleteResult deleteResult = (Engine.DeleteResult) result; response = new DeleteResponse( primary.shardId(), - requestToExecute.type(), requestToExecute.id(), deleteResult.getSeqNo(), result.getTerm(), diff --git a/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java index 945cc1621f19d..560fd1d8a45b3 100644 --- a/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java @@ -949,7 +949,6 @@ synchronized void markItemAsDropped(int slot) { indexRequest.opType(), new UpdateResponse( new ShardId(indexRequest.index(), IndexMetadata.INDEX_UUID_NA_VALUE, 0), - indexRequest.type(), id, SequenceNumbers.UNASSIGNED_SEQ_NO, SequenceNumbers.UNASSIGNED_PRIMARY_TERM, @@ -965,10 +964,9 @@ synchronized void markItemAsFailed(int slot, Exception e) { logger.debug( String.format( Locale.ROOT, - "failed to execute pipeline [%s] for document [%s/%s/%s]", + "failed to execute pipeline [%s] for document [%s/%s]", indexRequest.getPipeline(), indexRequest.index(), - indexRequest.type(), indexRequest.id() ), e diff --git a/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java b/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java index 5073adf13dc41..ed407bd37d684 100644 --- a/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java +++ b/server/src/main/java/org/opensearch/action/bulk/TransportShardBulkAction.java @@ -340,7 +340,7 @@ static boolean executeBulkItemRequest( final DeleteRequest request = context.getRequestToExecute(); result = primary.applyDeleteOperationOnPrimary( version, - request.type(), + MapperService.SINGLE_MAPPING_NAME, request.id(), request.versionType(), request.ifSeqNo(), @@ -353,7 +353,7 @@ static boolean executeBulkItemRequest( request.versionType(), new SourceToParse( request.index(), - request.type(), + MapperService.SINGLE_MAPPING_NAME, request.id(), request.source(), request.getContentType(), @@ -370,7 +370,7 @@ static boolean executeBulkItemRequest( try { primary.mapperService() .merge( - context.getRequestToExecute().type(), + MapperService.SINGLE_MAPPING_NAME, new CompressedXContent(result.getRequiredMappingUpdate(), XContentType.JSON, ToXContent.EMPTY_PARAMS), MapperService.MergeReason.MAPPING_UPDATE_PREFLIGHT ); @@ -383,7 +383,7 @@ static boolean executeBulkItemRequest( mappingUpdater.updateMappings( result.getRequiredMappingUpdate(), primary.shardId(), - context.getRequestToExecute().type(), + MapperService.SINGLE_MAPPING_NAME, new ActionListener() { @Override public void onResponse(Void v) { @@ -485,7 +485,6 @@ static BulkItemResponse processUpdateResponse( updateResponse = new UpdateResponse( indexResponse.getShardInfo(), indexResponse.getShardId(), - indexResponse.getType(), indexResponse.getId(), indexResponse.getSeqNo(), indexResponse.getPrimaryTerm(), @@ -518,7 +517,6 @@ static BulkItemResponse processUpdateResponse( updateResponse = new UpdateResponse( deleteResponse.getShardInfo(), deleteResponse.getShardId(), - deleteResponse.getType(), deleteResponse.getId(), deleteResponse.getSeqNo(), deleteResponse.getPrimaryTerm(), @@ -608,7 +606,7 @@ private static Engine.Result performOpOnReplica( final ShardId shardId = replica.shardId(); final SourceToParse sourceToParse = new SourceToParse( shardId.getIndexName(), - indexRequest.type(), + MapperService.SINGLE_MAPPING_NAME, indexRequest.id(), indexRequest.source(), indexRequest.getContentType(), @@ -629,7 +627,7 @@ private static Engine.Result performOpOnReplica( primaryResponse.getSeqNo(), primaryResponse.getPrimaryTerm(), primaryResponse.getVersion(), - deleteRequest.type(), + MapperService.SINGLE_MAPPING_NAME, deleteRequest.id() ); break; diff --git a/server/src/main/java/org/opensearch/action/delete/DeleteRequest.java b/server/src/main/java/org/opensearch/action/delete/DeleteRequest.java index e8175be08bc13..c40933ba9c92e 100644 --- a/server/src/main/java/org/opensearch/action/delete/DeleteRequest.java +++ b/server/src/main/java/org/opensearch/action/delete/DeleteRequest.java @@ -34,6 +34,7 @@ import org.apache.lucene.util.RamUsageEstimator; import org.opensearch.LegacyESVersion; +import org.opensearch.Version; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.CompositeIndicesRequest; import org.opensearch.action.DocWriteRequest; @@ -57,7 +58,7 @@ * A request to delete a document from an index based on its type and id. Best created using * {@link org.opensearch.client.Requests#deleteRequest(String)}. *

- * The operation requires the {@link #index()}, {@link #type(String)} and {@link #id(String)} to + * The operation requires the {@link #index()}, and {@link #id(String)} to * be set. * * @see DeleteResponse @@ -73,8 +74,6 @@ public class DeleteRequest extends ReplicatedWriteRequest private static final ShardId NO_SHARD_ID = null; - // Set to null initially so we can know to override in bulk requests that have a default type. - private String type; private String id; @Nullable private String routing; @@ -89,7 +88,10 @@ public DeleteRequest(StreamInput in) throws IOException { public DeleteRequest(@Nullable ShardId shardId, StreamInput in) throws IOException { super(shardId, in); - type = in.readString(); + if (in.getVersion().before(Version.V_2_0_0)) { + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but received [" + type + "]"; + } id = in.readString(); routing = in.readOptionalString(); if (in.getVersion().before(LegacyESVersion.V_7_0_0)) { @@ -106,7 +108,7 @@ public DeleteRequest() { } /** - * Constructs a new delete request against the specified index. The {@link #type(String)} and {@link #id(String)} + * Constructs a new delete request against the specified index. The {@link #id(String)} * must be set. */ public DeleteRequest(String index) { @@ -114,23 +116,6 @@ public DeleteRequest(String index) { this.index = index; } - /** - * Constructs a new delete request against the specified index with the type and id. - * - * @param index The index to get the document from - * @param type The type of the document - * @param id The id of the document - * - * @deprecated Types are in the process of being removed. Use {@link #DeleteRequest(String, String)} instead. - */ - @Deprecated - public DeleteRequest(String index, String type, String id) { - super(NO_SHARD_ID); - this.index = index; - this.type = type; - this.id = id; - } - /** * Constructs a new delete request against the specified index and id. * @@ -146,9 +131,6 @@ public DeleteRequest(String index, String id) { @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); - if (Strings.isEmpty(type())) { - validationException = addValidationError("type is missing", validationException); - } if (Strings.isEmpty(id)) { validationException = addValidationError("id is missing", validationException); } @@ -158,32 +140,6 @@ public ActionRequestValidationException validate() { return validationException; } - /** - * The type of the document to delete. - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - @Override - public String type() { - if (type == null) { - return MapperService.SINGLE_MAPPING_NAME; - } - return type; - } - - /** - * Sets the type of the document to delete. - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - @Override - public DeleteRequest type(String type) { - this.type = type; - return this; - } - /** * The id of the document to delete. */ @@ -317,9 +273,9 @@ public void writeThin(StreamOutput out) throws IOException { } private void writeBody(StreamOutput out) throws IOException { - // A 7.x request allows null types but if deserialized in a 6.x node will cause nullpointer exceptions. - // So we use the type accessor method here to make the type non-null (will default it to "_doc"). - out.writeString(type()); + if (out.getVersion().before(Version.V_2_0_0)) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + } out.writeString(id); out.writeOptionalString(routing()); if (out.getVersion().before(LegacyESVersion.V_7_0_0)) { @@ -333,7 +289,7 @@ private void writeBody(StreamOutput out) throws IOException { @Override public String toString() { - return "delete {[" + index + "][" + type() + "][" + id + "]}"; + return "delete {[" + index + "][" + id + "]}"; } @Override diff --git a/server/src/main/java/org/opensearch/action/delete/DeleteRequestBuilder.java b/server/src/main/java/org/opensearch/action/delete/DeleteRequestBuilder.java index f3d15cb9b0555..28abf092ad72d 100644 --- a/server/src/main/java/org/opensearch/action/delete/DeleteRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/delete/DeleteRequestBuilder.java @@ -55,9 +55,10 @@ public DeleteRequestBuilder(OpenSearchClient client, DeleteAction action, @Nulla /** * Sets the type of the document to delete. + * @deprecated types will be removed */ + @Deprecated public DeleteRequestBuilder setType(String type) { - request.type(type); return this; } diff --git a/server/src/main/java/org/opensearch/action/delete/DeleteResponse.java b/server/src/main/java/org/opensearch/action/delete/DeleteResponse.java index 21438313a7faa..6b000561ad282 100644 --- a/server/src/main/java/org/opensearch/action/delete/DeleteResponse.java +++ b/server/src/main/java/org/opensearch/action/delete/DeleteResponse.java @@ -58,12 +58,12 @@ public DeleteResponse(StreamInput in) throws IOException { super(in); } - public DeleteResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, boolean found) { - this(shardId, type, id, seqNo, primaryTerm, version, found ? Result.DELETED : Result.NOT_FOUND); + public DeleteResponse(ShardId shardId, String id, long seqNo, long primaryTerm, long version, boolean found) { + this(shardId, id, seqNo, primaryTerm, version, found ? Result.DELETED : Result.NOT_FOUND); } - private DeleteResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, Result result) { - super(shardId, type, id, seqNo, primaryTerm, version, assertDeletedOrNotFound(result)); + private DeleteResponse(ShardId shardId, String id, long seqNo, long primaryTerm, long version, Result result) { + super(shardId, id, seqNo, primaryTerm, version, assertDeletedOrNotFound(result)); } private static Result assertDeletedOrNotFound(Result result) { @@ -81,7 +81,6 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("DeleteResponse["); builder.append("index=").append(getIndex()); - builder.append(",type=").append(getType()); builder.append(",id=").append(getId()); builder.append(",version=").append(getVersion()); builder.append(",result=").append(getResult().getLowercase()); @@ -115,7 +114,7 @@ public static class Builder extends DocWriteResponse.Builder { @Override public DeleteResponse build() { - DeleteResponse deleteResponse = new DeleteResponse(shardId, type, id, seqNo, primaryTerm, version, result); + DeleteResponse deleteResponse = new DeleteResponse(shardId, id, seqNo, primaryTerm, version, result); deleteResponse.setForcedRefresh(forcedRefresh); if (shardInfo != null) { deleteResponse.setShardInfo(shardInfo); diff --git a/server/src/main/java/org/opensearch/action/index/IndexRequest.java b/server/src/main/java/org/opensearch/action/index/IndexRequest.java index 6831d498cf333..ed77774bc01d3 100644 --- a/server/src/main/java/org/opensearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/opensearch/action/index/IndexRequest.java @@ -47,7 +47,6 @@ import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.common.Nullable; -import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; @@ -77,7 +76,7 @@ * Index request to index a typed JSON document into a specific index and make it searchable. Best * created using {@link org.opensearch.client.Requests#indexRequest(String)}. * - * The index requires the {@link #index()}, {@link #type(String)}, {@link #id(String)} and + * The index requires the {@link #index()}, {@link #id(String)} and * {@link #source(byte[], XContentType)} to be set. * * The source (content to index) can be set in its bytes form using ({@link #source(byte[], XContentType)}), @@ -103,8 +102,6 @@ public class IndexRequest extends ReplicatedWriteRequest implement private static final ShardId NO_SHARD_ID = null; - // Set to null initially so we can know to override in bulk requests that have a default type. - private String type; private String id; @Nullable private String routing; @@ -143,7 +140,10 @@ public IndexRequest(StreamInput in) throws IOException { public IndexRequest(@Nullable ShardId shardId, StreamInput in) throws IOException { super(shardId, in); - type = in.readOptionalString(); + if (in.getVersion().before(Version.V_2_0_0)) { + String type = in.readOptionalString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but received [" + type + "]"; + } id = in.readOptionalString(); routing = in.readOptionalString(); if (in.getVersion().before(LegacyESVersion.V_7_0_0)) { @@ -181,7 +181,7 @@ public IndexRequest() { } /** - * Constructs a new index request against the specific index. The {@link #type(String)} + * Constructs a new index request against the specific index. The * {@link #source(byte[], XContentType)} must be set. */ public IndexRequest(String index) { @@ -189,44 +189,12 @@ public IndexRequest(String index) { this.index = index; } - /** - * Constructs a new index request against the specific index and type. The - * {@link #source(byte[], XContentType)} must be set. - * @deprecated Types are in the process of being removed. Use {@link #IndexRequest(String)} instead. - */ - @Deprecated - public IndexRequest(String index, String type) { - super(NO_SHARD_ID); - this.index = index; - this.type = type; - } - - /** - * Constructs a new index request against the index, type, id and using the source. - * - * @param index The index to index into - * @param type The type to index into - * @param id The id of document - * - * @deprecated Types are in the process of being removed. Use {@link #IndexRequest(String)} with {@link #id(String)} instead. - */ - @Deprecated - public IndexRequest(String index, String type, String id) { - super(NO_SHARD_ID); - this.index = index; - this.type = type; - this.id = id; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); if (source == null) { validationException = addValidationError("source is missing", validationException); } - if (Strings.isEmpty(type())) { - validationException = addValidationError("type is missing", validationException); - } if (contentType == null) { validationException = addValidationError("content type is missing", validationException); } @@ -298,30 +266,6 @@ public XContentType getContentType() { return contentType; } - /** - * The type of the indexed document. - * @deprecated Types are in the process of being removed. - */ - @Deprecated - @Override - public String type() { - if (type == null) { - return MapperService.SINGLE_MAPPING_NAME; - } - return type; - } - - /** - * Sets the type of the indexed document. - * @deprecated Types are in the process of being removed. - */ - @Deprecated - @Override - public IndexRequest type(String type) { - this.type = type; - return this; - } - /** * The id of the indexed document. If not set, will be automatically generated. */ @@ -672,7 +616,7 @@ public void process(Version indexCreatedVersion, @Nullable MappingMetadata mappi if (mappingMd != null) { // might as well check for routing here if (mappingMd.routing().required() && routing == null) { - throw new RoutingMissingException(concreteIndex, type(), id); + throw new RoutingMissingException(concreteIndex, id); } } @@ -718,9 +662,9 @@ public void writeThin(StreamOutput out) throws IOException { } private void writeBody(StreamOutput out) throws IOException { - // A 7.x request allows null types but if deserialized in a 6.x node will cause nullpointer exceptions. - // So we use the type accessor method here to make the type non-null (will default it to "_doc"). - out.writeOptionalString(type()); + if (out.getVersion().before(Version.V_2_0_0)) { + out.writeOptionalString(MapperService.SINGLE_MAPPING_NAME); + } out.writeOptionalString(id); out.writeOptionalString(routing); if (out.getVersion().before(LegacyESVersion.V_7_0_0)) { @@ -767,7 +711,7 @@ public String toString() { } catch (Exception e) { // ignore } - return "index {[" + index + "][" + type() + "][" + id + "], source[" + sSource + "]}"; + return "index {[" + index + "][" + id + "], source[" + sSource + "]}"; } @Override diff --git a/server/src/main/java/org/opensearch/action/index/IndexRequestBuilder.java b/server/src/main/java/org/opensearch/action/index/IndexRequestBuilder.java index ff13239717cda..f31efa3fc95d8 100644 --- a/server/src/main/java/org/opensearch/action/index/IndexRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/index/IndexRequestBuilder.java @@ -61,9 +61,10 @@ public IndexRequestBuilder(OpenSearchClient client, IndexAction action, @Nullabl /** * Sets the type to index the document to. + * @deprecated types will be removed */ + @Deprecated public IndexRequestBuilder setType(String type) { - request.type(type); return this; } diff --git a/server/src/main/java/org/opensearch/action/index/IndexResponse.java b/server/src/main/java/org/opensearch/action/index/IndexResponse.java index 9a25cbee43da2..be0826ce84f96 100644 --- a/server/src/main/java/org/opensearch/action/index/IndexResponse.java +++ b/server/src/main/java/org/opensearch/action/index/IndexResponse.java @@ -59,12 +59,12 @@ public IndexResponse(StreamInput in) throws IOException { super(in); } - public IndexResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, boolean created) { - this(shardId, type, id, seqNo, primaryTerm, version, created ? Result.CREATED : Result.UPDATED); + public IndexResponse(ShardId shardId, String id, long seqNo, long primaryTerm, long version, boolean created) { + this(shardId, id, seqNo, primaryTerm, version, created ? Result.CREATED : Result.UPDATED); } - private IndexResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, Result result) { - super(shardId, type, id, seqNo, primaryTerm, version, assertCreatedOrUpdated(result)); + private IndexResponse(ShardId shardId, String id, long seqNo, long primaryTerm, long version, Result result) { + super(shardId, id, seqNo, primaryTerm, version, assertCreatedOrUpdated(result)); } private static Result assertCreatedOrUpdated(Result result) { @@ -82,7 +82,6 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("IndexResponse["); builder.append("index=").append(getIndex()); - builder.append(",type=").append(getType()); builder.append(",id=").append(getId()); builder.append(",version=").append(getVersion()); builder.append(",result=").append(getResult().getLowercase()); @@ -117,7 +116,7 @@ public static void parseXContentFields(XContentParser parser, Builder context) t public static class Builder extends DocWriteResponse.Builder { @Override public IndexResponse build() { - IndexResponse indexResponse = new IndexResponse(shardId, type, id, seqNo, primaryTerm, version, result); + IndexResponse indexResponse = new IndexResponse(shardId, id, seqNo, primaryTerm, version, result); indexResponse.setForcedRefresh(forcedRefresh); if (shardInfo != null) { indexResponse.setShardInfo(shardInfo); diff --git a/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java b/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java index e8f7b901f6e9c..6223f25488d88 100644 --- a/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java +++ b/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java @@ -200,7 +200,6 @@ private static List parseDocs(Map config) { "[types removal] specifying _type in pipeline simulation requests is deprecated" ); } - String type = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.TYPE.getFieldName(), "_doc"); String id = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.ID.getFieldName(), "_id"); String routing = ConfigurationUtils.readOptionalStringOrIntProperty(null, null, dataMap, Metadata.ROUTING.getFieldName()); Long version = null; @@ -213,7 +212,7 @@ private static List parseDocs(Map config) { ConfigurationUtils.readStringProperty(null, null, dataMap, Metadata.VERSION_TYPE.getFieldName()) ); } - IngestDocument ingestDocument = new IngestDocument(index, type, id, routing, version, versionType, document); + IngestDocument ingestDocument = new IngestDocument(index, id, routing, version, versionType, document); if (dataMap.containsKey(Metadata.IF_SEQ_NO.getFieldName())) { Long ifSeqNo = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.IF_SEQ_NO.getFieldName()); ingestDocument.setFieldValue(Metadata.IF_SEQ_NO.getFieldName(), ifSeqNo); diff --git a/server/src/main/java/org/opensearch/action/ingest/WriteableIngestDocument.java b/server/src/main/java/org/opensearch/action/ingest/WriteableIngestDocument.java index 7b451b23d0a97..2f8c65486c22f 100644 --- a/server/src/main/java/org/opensearch/action/ingest/WriteableIngestDocument.java +++ b/server/src/main/java/org/opensearch/action/ingest/WriteableIngestDocument.java @@ -66,24 +66,22 @@ final class WriteableIngestDocument implements Writeable, ToXContentFragment { a -> { HashMap sourceAndMetadata = new HashMap<>(); sourceAndMetadata.put(Metadata.INDEX.getFieldName(), a[0]); - sourceAndMetadata.put(Metadata.TYPE.getFieldName(), a[1]); - sourceAndMetadata.put(Metadata.ID.getFieldName(), a[2]); + sourceAndMetadata.put(Metadata.ID.getFieldName(), a[1]); + if (a[2] != null) { + sourceAndMetadata.put(Metadata.ROUTING.getFieldName(), a[2]); + } if (a[3] != null) { - sourceAndMetadata.put(Metadata.ROUTING.getFieldName(), a[3]); + sourceAndMetadata.put(Metadata.VERSION.getFieldName(), a[3]); } if (a[4] != null) { - sourceAndMetadata.put(Metadata.VERSION.getFieldName(), a[4]); - } - if (a[5] != null) { - sourceAndMetadata.put(Metadata.VERSION_TYPE.getFieldName(), a[5]); + sourceAndMetadata.put(Metadata.VERSION_TYPE.getFieldName(), a[4]); } - sourceAndMetadata.putAll((Map) a[6]); - return new WriteableIngestDocument(new IngestDocument(sourceAndMetadata, (Map) a[7])); + sourceAndMetadata.putAll((Map) a[5]); + return new WriteableIngestDocument(new IngestDocument(sourceAndMetadata, (Map) a[6])); } ); static { INGEST_DOC_PARSER.declareString(constructorArg(), new ParseField(Metadata.INDEX.getFieldName())); - INGEST_DOC_PARSER.declareString(constructorArg(), new ParseField(Metadata.TYPE.getFieldName())); INGEST_DOC_PARSER.declareString(constructorArg(), new ParseField(Metadata.ID.getFieldName())); INGEST_DOC_PARSER.declareString(optionalConstructorArg(), new ParseField(Metadata.ROUTING.getFieldName())); INGEST_DOC_PARSER.declareLong(optionalConstructorArg(), new ParseField(Metadata.VERSION.getFieldName())); diff --git a/server/src/main/java/org/opensearch/action/update/TransportUpdateAction.java b/server/src/main/java/org/opensearch/action/update/TransportUpdateAction.java index 533d4f4918957..387c0d24ed4df 100644 --- a/server/src/main/java/org/opensearch/action/update/TransportUpdateAction.java +++ b/server/src/main/java/org/opensearch/action/update/TransportUpdateAction.java @@ -142,7 +142,7 @@ public static void resolveAndValidateRouting(Metadata metadata, String concreteI request.routing((metadata.resolveWriteIndexRouting(request.routing(), request.index()))); // Fail fast on the node that received the request, rather than failing when translating on the index or delete request. if (request.routing() == null && metadata.routingRequired(concreteIndex)) { - throw new RoutingMissingException(concreteIndex, request.type(), request.id()); + throw new RoutingMissingException(concreteIndex, request.id()); } } @@ -226,7 +226,6 @@ protected void shardOperation(final UpdateRequest request, final ActionListener< UpdateResponse update = new UpdateResponse( response.getShardInfo(), response.getShardId(), - response.getType(), response.getId(), response.getSeqNo(), response.getPrimaryTerm(), @@ -267,7 +266,6 @@ protected void shardOperation(final UpdateRequest request, final ActionListener< UpdateResponse update = new UpdateResponse( response.getShardInfo(), response.getShardId(), - response.getType(), response.getId(), response.getSeqNo(), response.getPrimaryTerm(), @@ -296,7 +294,6 @@ protected void shardOperation(final UpdateRequest request, final ActionListener< UpdateResponse update = new UpdateResponse( response.getShardInfo(), response.getShardId(), - response.getType(), response.getId(), response.getSeqNo(), response.getPrimaryTerm(), diff --git a/server/src/main/java/org/opensearch/action/update/UpdateHelper.java b/server/src/main/java/org/opensearch/action/update/UpdateHelper.java index 2621778e20eab..0da41a3028edf 100644 --- a/server/src/main/java/org/opensearch/action/update/UpdateHelper.java +++ b/server/src/main/java/org/opensearch/action/update/UpdateHelper.java @@ -51,7 +51,6 @@ import org.opensearch.index.engine.DocumentMissingException; import org.opensearch.index.engine.DocumentSourceMissingException; import org.opensearch.index.get.GetResult; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.RoutingFieldMapper; import org.opensearch.index.shard.IndexShard; import org.opensearch.index.shard.ShardId; @@ -97,7 +96,7 @@ protected Result prepare(ShardId shardId, UpdateRequest request, final GetResult return prepareUpsert(shardId, request, getResult, nowInMillis); } else if (getResult.internalSourceRef() == null) { // no source, we can't do anything, throw a failure... - throw new DocumentSourceMissingException(shardId, request.type(), request.id()); + throw new DocumentSourceMissingException(shardId, request.id()); } else if (request.script() == null && request.doc() != null) { // The request has no script, it is a new doc that should be merged with the old document return prepareUpdateIndexRequest(shardId, request, getResult, request.detectNoop()); @@ -138,7 +137,7 @@ Tuple> executeScriptedUpsert(Map PARSER.declareLong(UpdateRequest::setIfPrimaryTerm, IF_PRIMARY_TERM); } - // Set to null initially so we can know to override in bulk requests that have a default type. - private String type; private String id; @Nullable private String routing; @@ -160,7 +159,10 @@ public UpdateRequest(StreamInput in) throws IOException { public UpdateRequest(@Nullable ShardId shardId, StreamInput in) throws IOException { super(shardId, in); waitForActiveShards = ActiveShardCount.readFrom(in); - type = in.readString(); + if (in.getVersion().before(Version.V_2_0_0)) { + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but received [" + type + "]"; + } id = in.readString(); routing = in.readOptionalString(); if (in.getVersion().before(LegacyESVersion.V_7_0_0)) { @@ -210,25 +212,12 @@ public UpdateRequest(String index, String id) { this.id = id; } - /** - * @deprecated Types are in the process of being removed. Use {@link #UpdateRequest(String, String)} instead. - */ - @Deprecated - public UpdateRequest(String index, String type, String id) { - super(index); - this.type = type; - this.id = id; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = super.validate(); if (upsertRequest != null && upsertRequest.version() != Versions.MATCH_ANY) { validationException = addValidationError("can't provide version in upsert request", validationException); } - if (Strings.isEmpty(type())) { - validationException = addValidationError("type is missing", validationException); - } if (Strings.isEmpty(id)) { validationException = addValidationError("id is missing", validationException); } @@ -263,31 +252,6 @@ public ActionRequestValidationException validate() { return validationException; } - /** - * The type of the indexed document. - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - @Override - public String type() { - if (type == null) { - return MapperService.SINGLE_MAPPING_NAME; - } - return type; - } - - /** - * Sets the type of the indexed document. - * - * @deprecated Types are in the process of being removed. - */ - @Deprecated - public UpdateRequest type(String type) { - this.type = type; - return this; - } - /** * The id of the indexed document. */ @@ -919,9 +883,9 @@ public void writeThin(StreamOutput out) throws IOException { private void doWrite(StreamOutput out, boolean thin) throws IOException { waitForActiveShards.writeTo(out); - // A 7.x request allows null types but if deserialized in a 6.x node will cause nullpointer exceptions. - // So we use the type accessor method here to make the type non-null (will default it to "_doc"). - out.writeString(type()); + if (out.getVersion().before(Version.V_2_0_0)) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + } out.writeString(id); out.writeOptionalString(routing); if (out.getVersion().before(LegacyESVersion.V_7_0_0)) { @@ -941,7 +905,6 @@ private void doWrite(StreamOutput out, boolean thin) throws IOException { out.writeBoolean(true); // make sure the basics are set doc.index(index); - doc.type(type); doc.id(id); if (thin) { doc.writeThin(out); @@ -959,7 +922,6 @@ private void doWrite(StreamOutput out, boolean thin) throws IOException { out.writeBoolean(true); // make sure the basics are set upsertRequest.index(index); - upsertRequest.type(type); upsertRequest.id(id); if (thin) { upsertRequest.writeThin(out); @@ -1039,13 +1001,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - StringBuilder res = new StringBuilder().append("update {[") - .append(index) - .append("][") - .append(type()) - .append("][") - .append(id) - .append("]"); + StringBuilder res = new StringBuilder().append("update {[").append(index).append("][").append(id).append("]"); res.append(", doc_as_upsert[").append(docAsUpsert).append("]"); if (doc != null) { res.append(", doc[").append(doc).append("]"); diff --git a/server/src/main/java/org/opensearch/action/update/UpdateRequestBuilder.java b/server/src/main/java/org/opensearch/action/update/UpdateRequestBuilder.java index 3acbfe6dced12..fb8bf243a9fb5 100644 --- a/server/src/main/java/org/opensearch/action/update/UpdateRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/update/UpdateRequestBuilder.java @@ -54,15 +54,21 @@ public UpdateRequestBuilder(OpenSearchClient client, UpdateAction action) { super(client, action, new UpdateRequest()); } + @Deprecated public UpdateRequestBuilder(OpenSearchClient client, UpdateAction action, String index, String type, String id) { - super(client, action, new UpdateRequest(index, type, id)); + super(client, action, new UpdateRequest(index, id)); + } + + public UpdateRequestBuilder(OpenSearchClient client, UpdateAction action, String index, String id) { + super(client, action, new UpdateRequest(index, id)); } /** * Sets the type of the indexed document. + * @deprecated types will be removed */ + @Deprecated public UpdateRequestBuilder setType(String type) { - request.type(type); return this; } diff --git a/server/src/main/java/org/opensearch/action/update/UpdateResponse.java b/server/src/main/java/org/opensearch/action/update/UpdateResponse.java index 3f640b53d8b81..2c6efaf3c5f6b 100644 --- a/server/src/main/java/org/opensearch/action/update/UpdateResponse.java +++ b/server/src/main/java/org/opensearch/action/update/UpdateResponse.java @@ -38,7 +38,6 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.index.get.GetResult; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.shard.ShardId; import org.opensearch.rest.RestStatus; @@ -70,21 +69,12 @@ public UpdateResponse(StreamInput in) throws IOException { * Constructor to be used when a update didn't translate in a write. * For example: update script with operation set to none */ - public UpdateResponse(ShardId shardId, String type, String id, long seqNo, long primaryTerm, long version, Result result) { - this(new ShardInfo(0, 0), shardId, type, id, seqNo, primaryTerm, version, result); + public UpdateResponse(ShardId shardId, String id, long seqNo, long primaryTerm, long version, Result result) { + this(new ShardInfo(0, 0), shardId, id, seqNo, primaryTerm, version, result); } - public UpdateResponse( - ShardInfo shardInfo, - ShardId shardId, - String type, - String id, - long seqNo, - long primaryTerm, - long version, - Result result - ) { - super(shardId, MapperService.SINGLE_MAPPING_NAME, id, seqNo, primaryTerm, version, result); + public UpdateResponse(ShardInfo shardInfo, ShardId shardId, String id, long seqNo, long primaryTerm, long version, Result result) { + super(shardId, id, seqNo, primaryTerm, version, result); setShardInfo(shardInfo); } @@ -138,7 +128,6 @@ public String toString() { StringBuilder builder = new StringBuilder(); builder.append("UpdateResponse["); builder.append("index=").append(getIndex()); - builder.append(",type=").append(getType()); builder.append(",id=").append(getId()); builder.append(",version=").append(getVersion()); builder.append(",seqNo=").append(getSeqNo()); @@ -191,9 +180,9 @@ public void setGetResult(GetResult getResult) { public UpdateResponse build() { UpdateResponse update; if (shardInfo != null) { - update = new UpdateResponse(shardInfo, shardId, type, id, seqNo, primaryTerm, version, result); + update = new UpdateResponse(shardInfo, shardId, id, seqNo, primaryTerm, version, result); } else { - update = new UpdateResponse(shardId, type, id, seqNo, primaryTerm, version, result); + update = new UpdateResponse(shardId, id, seqNo, primaryTerm, version, result); } if (getResult != null) { update.setGetResult( diff --git a/server/src/main/java/org/opensearch/client/Requests.java b/server/src/main/java/org/opensearch/client/Requests.java index 762676586d8e0..d89f55a37a9cf 100644 --- a/server/src/main/java/org/opensearch/client/Requests.java +++ b/server/src/main/java/org/opensearch/client/Requests.java @@ -97,8 +97,8 @@ public static IndexRequest indexRequest() { } /** - * Create an index request against a specific index. Note the {@link IndexRequest#type(String)} must be - * set as well and optionally the {@link IndexRequest#id(String)}. + * Create an index request against a specific index. + * Note that setting {@link IndexRequest#id(String)} is optional. * * @param index The index name to index the request against * @return The index request @@ -109,8 +109,8 @@ public static IndexRequest indexRequest(String index) { } /** - * Creates a delete request against a specific index. Note the {@link DeleteRequest#type(String)} and - * {@link DeleteRequest#id(String)} must be set. + * Creates a delete request against a specific index. + * Note that {@link DeleteRequest#id(String)} must be set. * * @param index The index name to delete from * @return The delete request diff --git a/server/src/main/java/org/opensearch/index/engine/DocumentMissingException.java b/server/src/main/java/org/opensearch/index/engine/DocumentMissingException.java index 95ae422e73f64..9eb54292e13bd 100644 --- a/server/src/main/java/org/opensearch/index/engine/DocumentMissingException.java +++ b/server/src/main/java/org/opensearch/index/engine/DocumentMissingException.java @@ -39,8 +39,8 @@ public class DocumentMissingException extends EngineException { - public DocumentMissingException(ShardId shardId, String type, String id) { - super(shardId, "[" + type + "][" + id + "]: document missing"); + public DocumentMissingException(ShardId shardId, String id) { + super(shardId, "[" + id + "]: document missing"); } public DocumentMissingException(StreamInput in) throws IOException { diff --git a/server/src/main/java/org/opensearch/index/engine/DocumentSourceMissingException.java b/server/src/main/java/org/opensearch/index/engine/DocumentSourceMissingException.java index bfd595c9be5eb..333abc3794a5c 100644 --- a/server/src/main/java/org/opensearch/index/engine/DocumentSourceMissingException.java +++ b/server/src/main/java/org/opensearch/index/engine/DocumentSourceMissingException.java @@ -39,8 +39,8 @@ public class DocumentSourceMissingException extends EngineException { - public DocumentSourceMissingException(ShardId shardId, String type, String id) { - super(shardId, "[" + type + "][" + id + "]: document source missing"); + public DocumentSourceMissingException(ShardId shardId, String id) { + super(shardId, "[" + id + "]: document source missing"); } public DocumentSourceMissingException(StreamInput in) throws IOException { diff --git a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java index 7659afc87dcdf..5858b4b8108d2 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java +++ b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java @@ -50,7 +50,6 @@ import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.index.VersionType; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.query.QueryBuilder; import org.opensearch.script.Script; import org.opensearch.search.sort.SortOrder; @@ -209,14 +208,6 @@ public ReindexRequest setDestIndex(String destIndex) { return this; } - /** - * Set the document type for the destination index - */ - public ReindexRequest setDestDocType(String docType) { - this.getDestination().type(docType); - return this; - } - /** * Set the routing to decide which shard the documents need to be routed to */ @@ -303,9 +294,6 @@ public String toString() { } searchToString(b); b.append(" to [").append(destination.index()).append(']'); - if (destination.type() != null) { - b.append('[').append(destination.type()).append(']'); - } return b.toString(); } @@ -327,10 +315,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws // build destination builder.startObject("dest"); builder.field("index", getDestination().index()); - String type = getDestination().type(); - if (type != null && type.equals(MapperService.SINGLE_MAPPING_NAME) == false) { - builder.field("type", getDestination().type()); - } if (getDestination().routing() != null) { builder.field("routing", getDestination().routing()); } @@ -384,10 +368,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws ObjectParser destParser = new ObjectParser<>("dest"); destParser.declareString(IndexRequest::index, new ParseField("index")); - destParser.declareString((request, type) -> { - deprecationLogger.deprecate("reindex_with_types", TYPES_DEPRECATION_MESSAGE); - request.type(type); - }, new ParseField("type")); destParser.declareString(IndexRequest::routing, new ParseField("routing")); destParser.declareString(IndexRequest::opType, new ParseField("op_type")); destParser.declareString(IndexRequest::setPipeline, new ParseField("pipeline")); diff --git a/server/src/main/java/org/opensearch/index/reindex/ReindexRequestBuilder.java b/server/src/main/java/org/opensearch/index/reindex/ReindexRequestBuilder.java index a8d518414a53d..291acd1e8ad8d 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ReindexRequestBuilder.java +++ b/server/src/main/java/org/opensearch/index/reindex/ReindexRequestBuilder.java @@ -78,14 +78,6 @@ public ReindexRequestBuilder destination(String index) { return this; } - /** - * Set the destination index and type. - */ - public ReindexRequestBuilder destination(String index, String type) { - destination.setIndex(index).setType(type); - return this; - } - /** * Setup reindexing from a remote cluster. */ diff --git a/server/src/main/java/org/opensearch/ingest/IngestDocument.java b/server/src/main/java/org/opensearch/ingest/IngestDocument.java index 820763dde43cb..b496799c34dd0 100644 --- a/server/src/main/java/org/opensearch/ingest/IngestDocument.java +++ b/server/src/main/java/org/opensearch/ingest/IngestDocument.java @@ -76,19 +76,10 @@ public final class IngestDocument { // Contains all pipelines that have been executed for this document private final Set executedPipelines = new LinkedHashSet<>(); - public IngestDocument( - String index, - String type, - String id, - String routing, - Long version, - VersionType versionType, - Map source - ) { + public IngestDocument(String index, String id, String routing, Long version, VersionType versionType, Map source) { this.sourceAndMetadata = new HashMap<>(); this.sourceAndMetadata.putAll(source); this.sourceAndMetadata.put(Metadata.INDEX.getFieldName(), index); - this.sourceAndMetadata.put(Metadata.TYPE.getFieldName(), type); this.sourceAndMetadata.put(Metadata.ID.getFieldName(), id); if (routing != null) { this.sourceAndMetadata.put(Metadata.ROUTING.getFieldName(), routing); diff --git a/server/src/main/java/org/opensearch/ingest/IngestService.java b/server/src/main/java/org/opensearch/ingest/IngestService.java index f50d437c26fdb..cbd5fa71b27de 100644 --- a/server/src/main/java/org/opensearch/ingest/IngestService.java +++ b/server/src/main/java/org/opensearch/ingest/IngestService.java @@ -722,13 +722,12 @@ private void innerExecute( // (e.g. the pipeline may have been removed while we're ingesting a document totalMetrics.preIngest(); String index = indexRequest.index(); - String type = indexRequest.type(); String id = indexRequest.id(); String routing = indexRequest.routing(); Long version = indexRequest.version(); VersionType versionType = indexRequest.versionType(); Map sourceAsMap = indexRequest.sourceAsMap(); - IngestDocument ingestDocument = new IngestDocument(index, type, id, routing, version, versionType, sourceAsMap); + IngestDocument ingestDocument = new IngestDocument(index, id, routing, version, versionType, sourceAsMap); ingestDocument.executePipeline(pipeline, (result, e) -> { long ingestTimeInMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeInNanos); totalMetrics.postIngest(ingestTimeInMillis); @@ -743,7 +742,6 @@ private void innerExecute( // it's fine to set all metadata fields all the time, as ingest document holds their starting values // before ingestion, which might also get modified during ingestion. indexRequest.index((String) metadataMap.get(IngestDocument.Metadata.INDEX)); - indexRequest.type((String) metadataMap.get(IngestDocument.Metadata.TYPE)); indexRequest.id((String) metadataMap.get(IngestDocument.Metadata.ID)); indexRequest.routing((String) metadataMap.get(IngestDocument.Metadata.ROUTING)); indexRequest.version(((Number) metadataMap.get(IngestDocument.Metadata.VERSION)).longValue()); diff --git a/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java index 25a50a49d3aa0..f9f5933a44c95 100644 --- a/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/opensearch/rest/action/document/RestDeleteAction.java @@ -35,7 +35,6 @@ import org.opensearch.action.delete.DeleteRequest; import org.opensearch.action.support.ActiveShardCount; import org.opensearch.client.node.NodeClient; -import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.index.VersionType; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.RestRequest; @@ -50,19 +49,10 @@ import static org.opensearch.rest.RestRequest.Method.DELETE; public class RestDeleteAction extends BaseRestHandler { - private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestDeleteAction.class); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " - + "document index requests is deprecated, use the /{index}/_doc/{id} endpoint instead."; @Override public List routes() { - return unmodifiableList( - asList( - new Route(DELETE, "/{index}/_doc/{id}"), - // Deprecated typed endpoint. - new Route(DELETE, "/{index}/{type}/{id}") - ) - ); + return unmodifiableList(asList(new Route(DELETE, "/{index}/_doc/{id}"))); } @Override @@ -72,14 +62,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - DeleteRequest deleteRequest; - if (request.hasParam("type")) { - deprecationLogger.deprecate("delete_with_types", TYPES_DEPRECATION_MESSAGE); - deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id")); - } else { - deleteRequest = new DeleteRequest(request.param("index"), request.param("id")); - } - + DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("id")); deleteRequest.routing(request.param("routing")); deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT)); deleteRequest.setRefreshPolicy(request.param("refresh")); diff --git a/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java index 07e4723d35264..75f3967c32ba7 100644 --- a/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/opensearch/rest/action/document/RestIndexAction.java @@ -123,9 +123,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - IndexRequest indexRequest; - final String type = request.param("type"); - indexRequest = new IndexRequest(request.param("index")); + IndexRequest indexRequest = new IndexRequest(request.param("index")); indexRequest.id(request.param("id")); indexRequest.routing(request.param("routing")); indexRequest.setPipeline(request.param("pipeline")); diff --git a/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java b/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java index e80d5b1c70bd1..30dcaf8d9c1c1 100644 --- a/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java +++ b/server/src/test/java/org/opensearch/action/DocWriteResponseTests.java @@ -39,6 +39,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; +import org.opensearch.index.mapper.MapperService; import org.opensearch.index.seqno.SequenceNumbers; import org.opensearch.index.shard.ShardId; import org.opensearch.test.OpenSearchTestCase; @@ -53,7 +54,6 @@ public class DocWriteResponseTests extends OpenSearchTestCase { public void testGetLocation() { final DocWriteResponse response = new DocWriteResponse( new ShardId("index", "uuid", 0), - "type", "id", SequenceNumbers.UNASSIGNED_SEQ_NO, 17, @@ -61,14 +61,13 @@ public void testGetLocation() { Result.CREATED ) { }; - assertEquals("/index/type/id", response.getLocation(null)); - assertEquals("/index/type/id?routing=test_routing", response.getLocation("test_routing")); + assertEquals("/index/" + MapperService.SINGLE_MAPPING_NAME + "/id", response.getLocation(null)); + assertEquals("/index/" + MapperService.SINGLE_MAPPING_NAME + "/id?routing=test_routing", response.getLocation("test_routing")); } public void testGetLocationNonAscii() { final DocWriteResponse response = new DocWriteResponse( new ShardId("index", "uuid", 0), - "type", "❤", SequenceNumbers.UNASSIGNED_SEQ_NO, 17, @@ -76,14 +75,13 @@ public void testGetLocationNonAscii() { Result.CREATED ) { }; - assertEquals("/index/type/%E2%9D%A4", response.getLocation(null)); - assertEquals("/index/type/%E2%9D%A4?routing=%C3%A4", response.getLocation("ä")); + assertEquals("/index/" + MapperService.SINGLE_MAPPING_NAME + "/%E2%9D%A4", response.getLocation(null)); + assertEquals("/index/" + MapperService.SINGLE_MAPPING_NAME + "/%E2%9D%A4?routing=%C3%A4", response.getLocation("ä")); } public void testGetLocationWithSpaces() { final DocWriteResponse response = new DocWriteResponse( new ShardId("index", "uuid", 0), - "type", "a b", SequenceNumbers.UNASSIGNED_SEQ_NO, 17, @@ -91,8 +89,8 @@ public void testGetLocationWithSpaces() { Result.CREATED ) { }; - assertEquals("/index/type/a+b", response.getLocation(null)); - assertEquals("/index/type/a+b?routing=c+d", response.getLocation("c d")); + assertEquals("/index/" + MapperService.SINGLE_MAPPING_NAME + "/a+b", response.getLocation(null)); + assertEquals("/index/" + MapperService.SINGLE_MAPPING_NAME + "/a+b?routing=c+d", response.getLocation("c d")); } /** @@ -102,7 +100,6 @@ public void testGetLocationWithSpaces() { public void testToXContentDoesntIncludeForcedRefreshUnlessForced() throws IOException { DocWriteResponse response = new DocWriteResponse( new ShardId("index", "uuid", 0), - "type", "id", SequenceNumbers.UNASSIGNED_SEQ_NO, 17, diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkPrimaryExecutionContextTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkPrimaryExecutionContextTests.java index b98bdb2e3e40d..5159135a22618 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkPrimaryExecutionContextTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkPrimaryExecutionContextTests.java @@ -85,16 +85,16 @@ private BulkShardRequest generateRandomRequest() { final DocWriteRequest request; switch (randomFrom(DocWriteRequest.OpType.values())) { case INDEX: - request = new IndexRequest("index", "_doc", "id_" + i); + request = new IndexRequest("index").id("id_" + i); break; case CREATE: - request = new IndexRequest("index", "_doc", "id_" + i).create(true); + request = new IndexRequest("index").id("id_" + i).create(true); break; case UPDATE: - request = new UpdateRequest("index", "_doc", "id_" + i); + request = new UpdateRequest("index", "id_" + i); break; case DELETE: - request = new DeleteRequest("index", "_doc", "id_" + i); + request = new DeleteRequest("index", "id_" + i); break; default: throw new AssertionError("unknown type"); @@ -139,7 +139,7 @@ public void testTranslogLocation() { } break; case UPDATE: - context.setRequestToExecute(new IndexRequest(current.index(), current.type(), current.id())); + context.setRequestToExecute(new IndexRequest(current.index()).id(current.id())); if (failure) { result = new Engine.IndexResult(new OpenSearchException("bla"), 1, 1, 1); } else { diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkRequestModifierTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkRequestModifierTests.java index 5ab21518ddd21..e7e1166eb57fa 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkRequestModifierTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkRequestModifierTests.java @@ -58,7 +58,7 @@ public void testBulkRequestModifier() { int numRequests = scaledRandomIntBetween(8, 64); BulkRequest bulkRequest = new BulkRequest(); for (int i = 0; i < numRequests; i++) { - bulkRequest.add(new IndexRequest("_index", "_type", String.valueOf(i)).source("{}", XContentType.JSON)); + bulkRequest.add(new IndexRequest("_index").id(String.valueOf(i)).source("{}", XContentType.JSON)); } CaptureActionListener actionListener = new CaptureActionListener(); TransportBulkAction.BulkRequestModifier bulkRequestModifier = new TransportBulkAction.BulkRequestModifier(bulkRequest); @@ -98,7 +98,7 @@ public void testBulkRequestModifier() { public void testPipelineFailures() { BulkRequest originalBulkRequest = new BulkRequest(); for (int i = 0; i < 32; i++) { - originalBulkRequest.add(new IndexRequest("index", "type", String.valueOf(i))); + originalBulkRequest.add(new IndexRequest("index").id(String.valueOf(i))); } TransportBulkAction.BulkRequestModifier modifier = new TransportBulkAction.BulkRequestModifier(originalBulkRequest); @@ -127,15 +127,7 @@ public void onFailure(Exception e) {} List originalResponses = new ArrayList<>(); for (DocWriteRequest actionRequest : bulkRequest.requests()) { IndexRequest indexRequest = (IndexRequest) actionRequest; - IndexResponse indexResponse = new IndexResponse( - new ShardId("index", "_na_", 0), - indexRequest.type(), - indexRequest.id(), - 1, - 17, - 1, - true - ); + IndexResponse indexResponse = new IndexResponse(new ShardId("index", "_na_", 0), indexRequest.id(), 1, 17, 1, true); originalResponses.add(new BulkItemResponse(Integer.parseInt(indexRequest.id()), indexRequest.opType(), indexResponse)); } bulkResponseListener.onResponse(new BulkResponse(originalResponses.toArray(new BulkItemResponse[originalResponses.size()]), 0)); @@ -149,7 +141,7 @@ public void onFailure(Exception e) {} public void testNoFailures() { BulkRequest originalBulkRequest = new BulkRequest(); for (int i = 0; i < 32; i++) { - originalBulkRequest.add(new IndexRequest("index", "type", String.valueOf(i))); + originalBulkRequest.add(new IndexRequest("index").id(String.valueOf(i))); } TransportBulkAction.BulkRequestModifier modifier = new TransportBulkAction.BulkRequestModifier(originalBulkRequest); diff --git a/server/src/test/java/org/opensearch/action/bulk/BulkRequestTests.java b/server/src/test/java/org/opensearch/action/bulk/BulkRequestTests.java index fb7a4d4ef2169..9fd57a78d2097 100644 --- a/server/src/test/java/org/opensearch/action/bulk/BulkRequestTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/BulkRequestTests.java @@ -141,9 +141,9 @@ public void testBulkAllowExplicitIndex() throws Exception { public void testBulkAddIterable() { BulkRequest bulkRequest = Requests.bulkRequest(); List> requests = new ArrayList<>(); - requests.add(new IndexRequest("test", "test", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value")); - requests.add(new UpdateRequest("test", "test", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value")); - requests.add(new DeleteRequest("test", "test", "id")); + requests.add(new IndexRequest("test").id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value")); + requests.add(new UpdateRequest("test", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value")); + requests.add(new DeleteRequest("test", "id")); bulkRequest.add(requests); assertThat(bulkRequest.requests().size(), equalTo(3)); assertThat(bulkRequest.requests().get(0), instanceOf(IndexRequest.class)); @@ -251,12 +251,12 @@ public void testBulkEmptyObject() throws Exception { public void testBulkRequestWithRefresh() throws Exception { BulkRequest bulkRequest = new BulkRequest(); // We force here a "id is missing" validation error - bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); + bulkRequest.add(new DeleteRequest("index", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); // We force here a "type is missing" validation error - bulkRequest.add(new DeleteRequest("index", "", "id")); - bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE)); - bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); - bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); + bulkRequest.add(new DeleteRequest("index", "id")); + bulkRequest.add(new DeleteRequest("index", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE)); + bulkRequest.add(new UpdateRequest("index", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); + bulkRequest.add(new IndexRequest("index").id("id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE)); ActionRequestValidationException validate = bulkRequest.validate(); assertThat(validate, notNullValue()); assertThat(validate.validationErrors(), not(empty())); @@ -265,7 +265,6 @@ public void testBulkRequestWithRefresh() throws Exception { contains( "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "id is missing", - "type is missing", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead." @@ -276,8 +275,8 @@ public void testBulkRequestWithRefresh() throws Exception { // issue 15120 public void testBulkNoSource() throws Exception { BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add(new UpdateRequest("index", "type", "id")); - bulkRequest.add(new IndexRequest("index", "type", "id")); + bulkRequest.add(new UpdateRequest("index", "id")); + bulkRequest.add(new IndexRequest("index").id("id")); ActionRequestValidationException validate = bulkRequest.validate(); assertThat(validate, notNullValue()); assertThat(validate.validationErrors(), not(empty())); diff --git a/server/src/test/java/org/opensearch/action/bulk/RetryTests.java b/server/src/test/java/org/opensearch/action/bulk/RetryTests.java index 409367fa023a2..d3280ede6ce15 100644 --- a/server/src/test/java/org/opensearch/action/bulk/RetryTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/RetryTests.java @@ -87,11 +87,11 @@ public void tearDown() throws Exception { private BulkRequest createBulkRequest() { BulkRequest request = new BulkRequest(); - request.add(new UpdateRequest("shop", "products", "1")); - request.add(new UpdateRequest("shop", "products", "2")); - request.add(new UpdateRequest("shop", "products", "3")); - request.add(new UpdateRequest("shop", "products", "4")); - request.add(new UpdateRequest("shop", "products", "5")); + request.add(new UpdateRequest("shop", "1")); + request.add(new UpdateRequest("shop", "2")); + request.add(new UpdateRequest("shop", "3")); + request.add(new UpdateRequest("shop", "4")); + request.add(new UpdateRequest("shop", "5")); return request; } @@ -238,11 +238,7 @@ public void bulk(BulkRequest request, ActionListener listener) { } private BulkItemResponse successfulResponse() { - return new BulkItemResponse( - 1, - OpType.DELETE, - new DeleteResponse(new ShardId("test", "test", 0), "_doc", "test", 0, 0, 0, false) - ); + return new BulkItemResponse(1, OpType.DELETE, new DeleteResponse(new ShardId("test", "test", 0), "test", 0, 0, 0, false)); } private BulkItemResponse failedResponse() { diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java index b2f6ce885d242..32e9dd44008cd 100644 --- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java @@ -79,7 +79,7 @@ public void testNonExceptional() { bulkRequest.add(new IndexRequest(randomAlphaOfLength(5))); bulkRequest.add(new IndexRequest(randomAlphaOfLength(5))); bulkRequest.add(new DeleteRequest(randomAlphaOfLength(5))); - bulkRequest.add(new UpdateRequest(randomAlphaOfLength(5), randomAlphaOfLength(5), randomAlphaOfLength(5))); + bulkRequest.add(new UpdateRequest(randomAlphaOfLength(5), randomAlphaOfLength(5))); // Test emulating auto_create_index=false indicesThatCannotBeCreatedTestCase(emptySet(), bulkRequest, null); // Test emulating auto_create_index=true @@ -95,7 +95,7 @@ public void testAllFail() { bulkRequest.add(new IndexRequest("no")); bulkRequest.add(new IndexRequest("can't")); bulkRequest.add(new DeleteRequest("do").version(0).versionType(VersionType.EXTERNAL)); - bulkRequest.add(new UpdateRequest("nothin", randomAlphaOfLength(5), randomAlphaOfLength(5))); + bulkRequest.add(new UpdateRequest("nothin", randomAlphaOfLength(5))); indicesThatCannotBeCreatedTestCase( new HashSet<>(Arrays.asList("no", "can't", "do", "nothin")), bulkRequest, diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java index 8a804c5d7519e..4b98870422ce8 100644 --- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java @@ -290,7 +290,7 @@ public void setupAction() { public void testIngestSkipped() throws Exception { BulkRequest bulkRequest = new BulkRequest(); - IndexRequest indexRequest = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source(emptyMap()); bulkRequest.add(indexRequest); action.execute(null, bulkRequest, ActionListener.wrap(response -> {}, exception -> { throw new AssertionError(exception); })); @@ -299,7 +299,7 @@ public void testIngestSkipped() throws Exception { } public void testSingleItemBulkActionIngestSkipped() throws Exception { - IndexRequest indexRequest = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source(emptyMap()); singleItemBulkWriteAction.execute( null, @@ -313,10 +313,10 @@ public void testSingleItemBulkActionIngestSkipped() throws Exception { public void testIngestLocal() throws Exception { Exception exception = new Exception("fake exception"); BulkRequest bulkRequest = new BulkRequest(); - IndexRequest indexRequest1 = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest1 = new IndexRequest("index").id("id"); indexRequest1.source(emptyMap()); indexRequest1.setPipeline("testpipeline"); - IndexRequest indexRequest2 = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest2 = new IndexRequest("index").id("id"); indexRequest2.source(emptyMap()); indexRequest2.setPipeline("testpipeline"); bulkRequest.add(indexRequest1); @@ -360,7 +360,7 @@ public void testIngestLocal() throws Exception { public void testSingleItemBulkActionIngestLocal() throws Exception { Exception exception = new Exception("fake exception"); - IndexRequest indexRequest = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source(emptyMap()); indexRequest.setPipeline("testpipeline"); AtomicBoolean responseCalled = new AtomicBoolean(false); @@ -444,7 +444,7 @@ public void testIngestSystemLocal() throws Exception { public void testIngestForward() throws Exception { localIngest = false; BulkRequest bulkRequest = new BulkRequest(); - IndexRequest indexRequest = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source(emptyMap()); indexRequest.setPipeline("testpipeline"); bulkRequest.add(indexRequest); @@ -485,7 +485,7 @@ public void testIngestForward() throws Exception { public void testSingleItemBulkActionIngestForward() throws Exception { localIngest = false; - IndexRequest indexRequest = new IndexRequest("index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source(emptyMap()); indexRequest.setPipeline("testpipeline"); IndexResponse indexResponse = mock(IndexResponse.class); @@ -527,11 +527,11 @@ public void testSingleItemBulkActionIngestForward() throws Exception { } public void testUseDefaultPipeline() throws Exception { - validateDefaultPipeline(new IndexRequest(WITH_DEFAULT_PIPELINE, "type", "id")); + validateDefaultPipeline(new IndexRequest(WITH_DEFAULT_PIPELINE).id("id")); } public void testUseDefaultPipelineWithAlias() throws Exception { - validateDefaultPipeline(new IndexRequest(WITH_DEFAULT_PIPELINE_ALIAS, "type", "id")); + validateDefaultPipeline(new IndexRequest(WITH_DEFAULT_PIPELINE_ALIAS).id("id")); } public void testUseDefaultPipelineWithBulkUpsert() throws Exception { @@ -547,15 +547,14 @@ public void testUseDefaultPipelineWithBulkUpsertWithAlias() throws Exception { private void validatePipelineWithBulkUpsert(@Nullable String indexRequestIndexName, String updateRequestIndexName) throws Exception { Exception exception = new Exception("fake exception"); BulkRequest bulkRequest = new BulkRequest(); - IndexRequest indexRequest1 = new IndexRequest(indexRequestIndexName, "type", "id1").source(emptyMap()); - IndexRequest indexRequest2 = new IndexRequest(indexRequestIndexName, "type", "id2").source(emptyMap()); - IndexRequest indexRequest3 = new IndexRequest(indexRequestIndexName, "type", "id3").source(emptyMap()); - UpdateRequest upsertRequest = new UpdateRequest(updateRequestIndexName, "type", "id1").upsert(indexRequest1) - .script(mockScript("1")); - UpdateRequest docAsUpsertRequest = new UpdateRequest(updateRequestIndexName, "type", "id2").doc(indexRequest2).docAsUpsert(true); + IndexRequest indexRequest1 = new IndexRequest(indexRequestIndexName).id("id1").source(emptyMap()); + IndexRequest indexRequest2 = new IndexRequest(indexRequestIndexName).id("id2").source(emptyMap()); + IndexRequest indexRequest3 = new IndexRequest(indexRequestIndexName).id("id3").source(emptyMap()); + UpdateRequest upsertRequest = new UpdateRequest(updateRequestIndexName, "id1").upsert(indexRequest1).script(mockScript("1")); + UpdateRequest docAsUpsertRequest = new UpdateRequest(updateRequestIndexName, "id2").doc(indexRequest2).docAsUpsert(true); // this test only covers the mechanics that scripted bulk upserts will execute a default pipeline. However, in practice scripted // bulk upserts with a default pipeline are a bit surprising since the script executes AFTER the pipeline. - UpdateRequest scriptedUpsert = new UpdateRequest(updateRequestIndexName, "type", "id2").upsert(indexRequest3) + UpdateRequest scriptedUpsert = new UpdateRequest(updateRequestIndexName, "id2").upsert(indexRequest3) .script(mockScript("1")) .scriptedUpsert(true); bulkRequest.add(upsertRequest).add(docAsUpsertRequest).add(scriptedUpsert); @@ -604,7 +603,7 @@ private void validatePipelineWithBulkUpsert(@Nullable String indexRequestIndexNa public void testDoExecuteCalledTwiceCorrectly() throws Exception { Exception exception = new Exception("fake exception"); - IndexRequest indexRequest = new IndexRequest("missing_index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("missing_index").id("id"); indexRequest.setPipeline("testpipeline"); indexRequest.source(emptyMap()); AtomicBoolean responseCalled = new AtomicBoolean(false); @@ -644,7 +643,7 @@ public void testDoExecuteCalledTwiceCorrectly() throws Exception { public void testNotFindDefaultPipelineFromTemplateMatches() { Exception exception = new Exception("fake exception"); - IndexRequest indexRequest = new IndexRequest("missing_index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("missing_index").id("id"); indexRequest.source(emptyMap()); AtomicBoolean responseCalled = new AtomicBoolean(false); AtomicBoolean failureCalled = new AtomicBoolean(false); @@ -698,7 +697,7 @@ public void testFindDefaultPipelineFromTemplateMatch() { when(metadata.getTemplates()).thenReturn(templateMetadataBuilder.build()); when(metadata.indices()).thenReturn(ImmutableOpenMap.of()); - IndexRequest indexRequest = new IndexRequest("missing_index", "type", "id"); + IndexRequest indexRequest = new IndexRequest("missing_index").id("id"); indexRequest.source(emptyMap()); AtomicBoolean responseCalled = new AtomicBoolean(false); AtomicBoolean failureCalled = new AtomicBoolean(false); diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java index 0ce8a2fc1a2ed..5eb395cb05971 100644 --- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java @@ -168,7 +168,7 @@ public void tearDown() throws Exception { } public void testDeleteNonExistingDocDoesNotCreateIndex() throws Exception { - BulkRequest bulkRequest = new BulkRequest().add(new DeleteRequest("index", "type", "id")); + BulkRequest bulkRequest = new BulkRequest().add(new DeleteRequest("index", "id")); PlainActionFuture future = PlainActionFuture.newFuture(); ActionTestUtils.execute(bulkAction, null, bulkRequest, future); @@ -183,9 +183,7 @@ public void testDeleteNonExistingDocDoesNotCreateIndex() throws Exception { } public void testDeleteNonExistingDocExternalVersionCreatesIndex() throws Exception { - BulkRequest bulkRequest = new BulkRequest().add( - new DeleteRequest("index", "type", "id").versionType(VersionType.EXTERNAL).version(0) - ); + BulkRequest bulkRequest = new BulkRequest().add(new DeleteRequest("index", "id").versionType(VersionType.EXTERNAL).version(0)); PlainActionFuture future = PlainActionFuture.newFuture(); ActionTestUtils.execute(bulkAction, null, bulkRequest, future); @@ -194,9 +192,7 @@ public void testDeleteNonExistingDocExternalVersionCreatesIndex() throws Excepti } public void testDeleteNonExistingDocExternalGteVersionCreatesIndex() throws Exception { - BulkRequest bulkRequest = new BulkRequest().add( - new DeleteRequest("index2", "type", "id").versionType(VersionType.EXTERNAL_GTE).version(0) - ); + BulkRequest bulkRequest = new BulkRequest().add(new DeleteRequest("index2", "id").versionType(VersionType.EXTERNAL_GTE).version(0)); PlainActionFuture future = PlainActionFuture.newFuture(); ActionTestUtils.execute(bulkAction, null, bulkRequest, future); @@ -205,12 +201,10 @@ public void testDeleteNonExistingDocExternalGteVersionCreatesIndex() throws Exce } public void testGetIndexWriteRequest() throws Exception { - IndexRequest indexRequest = new IndexRequest("index", "type", "id1").source(emptyMap()); - UpdateRequest upsertRequest = new UpdateRequest("index", "type", "id1").upsert(indexRequest).script(mockScript("1")); - UpdateRequest docAsUpsertRequest = new UpdateRequest("index", "type", "id2").doc(indexRequest).docAsUpsert(true); - UpdateRequest scriptedUpsert = new UpdateRequest("index", "type", "id2").upsert(indexRequest) - .script(mockScript("1")) - .scriptedUpsert(true); + IndexRequest indexRequest = new IndexRequest("index").id("id1").source(emptyMap()); + UpdateRequest upsertRequest = new UpdateRequest("index", "id1").upsert(indexRequest).script(mockScript("1")); + UpdateRequest docAsUpsertRequest = new UpdateRequest("index", "id2").doc(indexRequest).docAsUpsert(true); + UpdateRequest scriptedUpsert = new UpdateRequest("index", "id2").upsert(indexRequest).script(mockScript("1")).scriptedUpsert(true); assertEquals(TransportBulkAction.getIndexWriteRequest(indexRequest), indexRequest); assertEquals(TransportBulkAction.getIndexWriteRequest(upsertRequest), indexRequest); @@ -220,7 +214,7 @@ public void testGetIndexWriteRequest() throws Exception { DeleteRequest deleteRequest = new DeleteRequest("index", "id"); assertNull(TransportBulkAction.getIndexWriteRequest(deleteRequest)); - UpdateRequest badUpsertRequest = new UpdateRequest("index", "type", "id1"); + UpdateRequest badUpsertRequest = new UpdateRequest("index", "id1"); assertNull(TransportBulkAction.getIndexWriteRequest(badUpsertRequest)); } diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportShardBulkActionTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportShardBulkActionTests.java index 038b0efa500fb..733d09126004b 100644 --- a/server/src/test/java/org/opensearch/action/bulk/TransportShardBulkActionTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/TransportShardBulkActionTests.java @@ -122,8 +122,7 @@ public void testExecuteBulkIndexRequest() throws Exception { BulkItemRequest[] items = new BulkItemRequest[1]; boolean create = randomBoolean(); - DocWriteRequest writeRequest = new IndexRequest("index", "_doc", "id").source(Requests.INDEX_CONTENT_TYPE) - .create(create); + DocWriteRequest writeRequest = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE).create(create); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); items[0] = primaryRequest; BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); @@ -154,7 +153,7 @@ public void testExecuteBulkIndexRequest() throws Exception { // Assert that the document actually made it there assertDocCount(shard, 1); - writeRequest = new IndexRequest("index", "_doc", "id").source(Requests.INDEX_CONTENT_TYPE).create(true); + writeRequest = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE).create(true); primaryRequest = new BulkItemRequest(0, writeRequest); items[0] = primaryRequest; bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); @@ -203,7 +202,8 @@ public void testSkipBulkIndexRequestIfAborted() throws Exception { BulkItemRequest[] items = new BulkItemRequest[randomIntBetween(2, 5)]; for (int i = 0; i < items.length; i++) { - DocWriteRequest writeRequest = new IndexRequest("index", "_doc", "id_" + i).source(Requests.INDEX_CONTENT_TYPE) + DocWriteRequest writeRequest = new IndexRequest("index").id("id_" + i) + .source(Requests.INDEX_CONTENT_TYPE) .opType(DocWriteRequest.OpType.INDEX); items[i] = new BulkItemRequest(i, writeRequest); } @@ -264,11 +264,7 @@ public void testSkipBulkIndexRequestIfAborted() throws Exception { public void testExecuteBulkIndexRequestWithMappingUpdates() throws Exception { BulkItemRequest[] items = new BulkItemRequest[1]; - DocWriteRequest writeRequest = new IndexRequest("index", "_doc", "id").source( - Requests.INDEX_CONTENT_TYPE, - "foo", - "bar" - ); + DocWriteRequest writeRequest = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar"); items[0] = new BulkItemRequest(0, writeRequest); BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); @@ -342,11 +338,7 @@ public void testExecuteBulkIndexRequestWithErrorWhileUpdatingMapping() throws Ex IndexShard shard = newStartedShard(true); BulkItemRequest[] items = new BulkItemRequest[1]; - DocWriteRequest writeRequest = new IndexRequest("index", "_doc", "id").source( - Requests.INDEX_CONTENT_TYPE, - "foo", - "bar" - ); + DocWriteRequest writeRequest = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar"); items[0] = new BulkItemRequest(0, writeRequest); BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); @@ -402,7 +394,7 @@ public void testExecuteBulkDeleteRequest() throws Exception { IndexShard shard = newStartedShard(true); BulkItemRequest[] items = new BulkItemRequest[1]; - DocWriteRequest writeRequest = new DeleteRequest("index", "_doc", "id"); + DocWriteRequest writeRequest = new DeleteRequest("index", "id"); items[0] = new BulkItemRequest(0, writeRequest); BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); @@ -441,7 +433,6 @@ public void testExecuteBulkDeleteRequest() throws Exception { assertThat(response.getResult(), equalTo(DocWriteResponse.Result.NOT_FOUND)); assertThat(response.getShardId(), equalTo(shard.shardId())); assertThat(response.getIndex(), equalTo("index")); - assertThat(response.getType(), equalTo("_doc")); assertThat(response.getId(), equalTo("id")); assertThat(response.getVersion(), equalTo(1L)); assertThat(response.getSeqNo(), equalTo(0L)); @@ -450,7 +441,7 @@ public void testExecuteBulkDeleteRequest() throws Exception { // Now do the same after indexing the document, it should now find and delete the document indexDoc(shard, "_doc", "id", "{}"); - writeRequest = new DeleteRequest("index", "_doc", "id"); + writeRequest = new DeleteRequest("index", "id"); items[0] = new BulkItemRequest(0, writeRequest); bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items); @@ -489,7 +480,6 @@ public void testExecuteBulkDeleteRequest() throws Exception { assertThat(response.getResult(), equalTo(DocWriteResponse.Result.DELETED)); assertThat(response.getShardId(), equalTo(shard.shardId())); assertThat(response.getIndex(), equalTo("index")); - assertThat(response.getType(), equalTo("_doc")); assertThat(response.getId(), equalTo("id")); assertThat(response.getVersion(), equalTo(3L)); assertThat(response.getSeqNo(), equalTo(2L)); @@ -500,14 +490,10 @@ public void testExecuteBulkDeleteRequest() throws Exception { } public void testNoopUpdateRequest() throws Exception { - DocWriteRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + DocWriteRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); - DocWriteResponse noopUpdateResponse = new UpdateResponse(shardId, "_doc", "id", 0, 2, 1, DocWriteResponse.Result.NOOP); + DocWriteResponse noopUpdateResponse = new UpdateResponse(shardId, "id", 0, 2, 1, DocWriteResponse.Result.NOOP); IndexShard shard = mock(IndexShard.class); @@ -553,14 +539,10 @@ public void testNoopUpdateRequest() throws Exception { public void testUpdateRequestWithFailure() throws Exception { IndexSettings indexSettings = new IndexSettings(indexMetadata(), Settings.EMPTY); - DocWriteRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + DocWriteRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); - IndexRequest updateResponse = new IndexRequest("index", "_doc", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); + IndexRequest updateResponse = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); Exception err = new OpenSearchException("I'm dead <(x.x)>"); Engine.IndexResult indexResult = new Engine.IndexResult(err, 0, 0, 0); @@ -614,14 +596,10 @@ public void testUpdateRequestWithFailure() throws Exception { public void testUpdateRequestWithConflictFailure() throws Exception { IndexSettings indexSettings = new IndexSettings(indexMetadata(), Settings.EMPTY); - DocWriteRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + DocWriteRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); - IndexRequest updateResponse = new IndexRequest("index", "_doc", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); + IndexRequest updateResponse = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); Exception err = new VersionConflictEngineException(shardId, "id", "I'm conflicted <(;_;)>"); Engine.IndexResult indexResult = new Engine.IndexResult(err, 0, 0, 0); @@ -673,14 +651,10 @@ public void testUpdateRequestWithConflictFailure() throws Exception { public void testUpdateRequestWithSuccess() throws Exception { IndexSettings indexSettings = new IndexSettings(indexMetadata(), Settings.EMPTY); - DocWriteRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + DocWriteRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); - IndexRequest updateResponse = new IndexRequest("index", "_doc", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); + IndexRequest updateResponse = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); boolean created = randomBoolean(); Translog.Location resultLocation = new Translog.Location(42, 42, 42); @@ -734,14 +708,10 @@ public void testUpdateRequestWithSuccess() throws Exception { public void testUpdateWithDelete() throws Exception { IndexSettings indexSettings = new IndexSettings(indexMetadata(), Settings.EMPTY); - DocWriteRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + DocWriteRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); - DeleteRequest updateResponse = new DeleteRequest("index", "_doc", "id"); + DeleteRequest updateResponse = new DeleteRequest("index", "id"); boolean found = randomBoolean(); Translog.Location resultLocation = new Translog.Location(42, 42, 42); @@ -791,11 +761,7 @@ public void testUpdateWithDelete() throws Exception { } public void testFailureDuringUpdateProcessing() throws Exception { - DocWriteRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc( - Requests.INDEX_CONTENT_TYPE, - "field", - "value" - ); + DocWriteRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); IndexShard shard = mock(IndexShard.class); @@ -838,7 +804,8 @@ public void testTranslogPositionToSync() throws Exception { BulkItemRequest[] items = new BulkItemRequest[randomIntBetween(2, 5)]; for (int i = 0; i < items.length; i++) { - DocWriteRequest writeRequest = new IndexRequest("index", "_doc", "id_" + i).source(Requests.INDEX_CONTENT_TYPE) + DocWriteRequest writeRequest = new IndexRequest("index").id("id_" + i) + .source(Requests.INDEX_CONTENT_TYPE) .opType(DocWriteRequest.OpType.INDEX); items[i] = new BulkItemRequest(i, writeRequest); } @@ -875,7 +842,7 @@ public void testTranslogPositionToSync() throws Exception { public void testNoOpReplicationOnPrimaryDocumentFailure() throws Exception { final IndexShard shard = spy(newStartedShard(false)); - BulkItemRequest itemRequest = new BulkItemRequest(0, new IndexRequest("index", "_doc").source(Requests.INDEX_CONTENT_TYPE)); + BulkItemRequest itemRequest = new BulkItemRequest(0, new IndexRequest("index").source(Requests.INDEX_CONTENT_TYPE)); final String failureMessage = "simulated primary failure"; final IOException exception = new IOException(failureMessage); itemRequest.setPrimaryResponse( @@ -895,12 +862,12 @@ public void testNoOpReplicationOnPrimaryDocumentFailure() throws Exception { public void testRetries() throws Exception { IndexSettings indexSettings = new IndexSettings(indexMetadata(), Settings.EMPTY); - UpdateRequest writeRequest = new UpdateRequest("index", "_doc", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); + UpdateRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"); // the beating will continue until success has come. writeRequest.retryOnConflict(Integer.MAX_VALUE); BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest); - IndexRequest updateResponse = new IndexRequest("index", "_doc", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); + IndexRequest updateResponse = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"); Exception err = new VersionConflictEngineException(shardId, "id", "I'm conflicted <(;_;)>"); Engine.IndexResult conflictedResult = new Engine.IndexResult(err, 0); @@ -1078,7 +1045,7 @@ private void randomlySetIgnoredPrimaryResponse(BulkItemRequest primaryRequest) { new BulkItemResponse( 0, DocWriteRequest.OpType.INDEX, - new IndexResponse(shardId, "_doc", "ignore-primary-response-on-primary", 42, 42, 42, false) + new IndexResponse(shardId, "ignore-primary-response-on-primary", 42, 42, 42, false) ) ); } diff --git a/server/src/test/java/org/opensearch/action/delete/DeleteRequestTests.java b/server/src/test/java/org/opensearch/action/delete/DeleteRequestTests.java index acd07b781be0a..0dda8969e7d74 100644 --- a/server/src/test/java/org/opensearch/action/delete/DeleteRequestTests.java +++ b/server/src/test/java/org/opensearch/action/delete/DeleteRequestTests.java @@ -42,23 +42,14 @@ public class DeleteRequestTests extends OpenSearchTestCase { public void testValidation() { { - final DeleteRequest request = new DeleteRequest("index4", "_doc", "0"); + final DeleteRequest request = new DeleteRequest("index4", "0"); final ActionRequestValidationException validate = request.validate(); assertThat(validate, nullValue()); } { - // Empty types are accepted but fail validation - final DeleteRequest request = new DeleteRequest("index4", "", randomBoolean() ? "" : null); - final ActionRequestValidationException validate = request.validate(); - - assertThat(validate, not(nullValue())); - assertThat(validate.validationErrors(), hasItems("type is missing", "id is missing")); - } - { - // Null types are defaulted - final DeleteRequest request = new DeleteRequest("index4", randomBoolean() ? "" : null); + final DeleteRequest request = new DeleteRequest("index4", null); final ActionRequestValidationException validate = request.validate(); assertThat(validate, not(nullValue())); diff --git a/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java b/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java index 5b2a1d61614cb..e6c80b8ebdb61 100644 --- a/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java +++ b/server/src/test/java/org/opensearch/action/delete/DeleteResponseTests.java @@ -55,21 +55,21 @@ public class DeleteResponseTests extends OpenSearchTestCase { public void testToXContent() { { - DeleteResponse response = new DeleteResponse(new ShardId("index", "index_uuid", 0), "type", "id", 3, 17, 5, true); + DeleteResponse response = new DeleteResponse(new ShardId("index", "index_uuid", 0), "id", 3, 17, 5, true); String output = Strings.toString(response); assertEquals( - "{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":5,\"result\":\"deleted\"," + "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":5,\"result\":\"deleted\"," + "\"_shards\":null,\"_seq_no\":3,\"_primary_term\":17}", output ); } { - DeleteResponse response = new DeleteResponse(new ShardId("index", "index_uuid", 0), "type", "id", -1, 0, 7, true); + DeleteResponse response = new DeleteResponse(new ShardId("index", "index_uuid", 0), "id", -1, 0, 7, true); response.setForcedRefresh(true); response.setShardInfo(new ReplicationResponse.ShardInfo(10, 5)); String output = Strings.toString(response); assertEquals( - "{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":7,\"result\":\"deleted\"," + "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":7,\"result\":\"deleted\"," + "\"forced_refresh\":true,\"_shards\":{\"total\":10,\"successful\":5,\"failed\":0}}", output ); @@ -141,19 +141,11 @@ public static Tuple randomDeleteResponse() { Tuple shardInfos = RandomObjects.randomShardInfo(random()); - DeleteResponse actual = new DeleteResponse(new ShardId(index, indexUUid, shardId), type, id, seqNo, primaryTerm, version, found); + DeleteResponse actual = new DeleteResponse(new ShardId(index, indexUUid, shardId), id, seqNo, primaryTerm, version, found); actual.setForcedRefresh(forcedRefresh); actual.setShardInfo(shardInfos.v1()); - DeleteResponse expected = new DeleteResponse( - new ShardId(index, INDEX_UUID_NA_VALUE, -1), - type, - id, - seqNo, - primaryTerm, - version, - found - ); + DeleteResponse expected = new DeleteResponse(new ShardId(index, INDEX_UUID_NA_VALUE, -1), id, seqNo, primaryTerm, version, found); expected.setForcedRefresh(forcedRefresh); expected.setShardInfo(shardInfos.v2()); diff --git a/server/src/test/java/org/opensearch/action/index/IndexRequestTests.java b/server/src/test/java/org/opensearch/action/index/IndexRequestTests.java index 16d7b0348b7de..21305957d802b 100644 --- a/server/src/test/java/org/opensearch/action/index/IndexRequestTests.java +++ b/server/src/test/java/org/opensearch/action/index/IndexRequestTests.java @@ -137,11 +137,10 @@ public void testAutoGenIdTimestampIsSet() { public void testIndexResponse() { ShardId shardId = new ShardId(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), randomIntBetween(0, 1000)); - String type = randomAlphaOfLengthBetween(3, 10); String id = randomAlphaOfLengthBetween(3, 10); long version = randomLong(); boolean created = randomBoolean(); - IndexResponse indexResponse = new IndexResponse(shardId, type, id, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, version, created); + IndexResponse indexResponse = new IndexResponse(shardId, id, SequenceNumbers.UNASSIGNED_SEQ_NO, 0, version, created); int total = randomIntBetween(1, 10); int successful = randomIntBetween(1, 10); ReplicationResponse.ShardInfo shardInfo = new ReplicationResponse.ShardInfo(total, successful); @@ -151,7 +150,6 @@ public void testIndexResponse() { forcedRefresh = randomBoolean(); indexResponse.setForcedRefresh(forcedRefresh); } - assertEquals(type, indexResponse.getType()); assertEquals(id, indexResponse.getId()); assertEquals(version, indexResponse.getVersion()); assertEquals(shardId, indexResponse.getShardId()); @@ -162,8 +160,6 @@ public void testIndexResponse() { assertEquals( "IndexResponse[index=" + shardId.getIndexName() - + ",type=" - + type + ",id=" + id + ",version=" @@ -220,13 +216,13 @@ public void testToStringSizeLimit() throws UnsupportedEncodingException { String source = "{\"name\":\"value\"}"; request.source(source, XContentType.JSON); - assertEquals("index {[index][_doc][null], source[" + source + "]}", request.toString()); + assertEquals("index {[index][null], source[" + source + "]}", request.toString()); source = "{\"name\":\"" + randomUnicodeOfLength(IndexRequest.MAX_SOURCE_LENGTH_IN_TOSTRING) + "\"}"; request.source(source, XContentType.JSON); int actualBytes = source.getBytes("UTF-8").length; assertEquals( - "index {[index][_doc][null], source[n/a, actual length: [" + "index {[index][null], source[n/a, actual length: [" + new ByteSizeValue(actualBytes).toString() + "], max length: " + new ByteSizeValue(IndexRequest.MAX_SOURCE_LENGTH_IN_TOSTRING).toString() diff --git a/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java b/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java index ebe8d0b2aaa1b..25d6a60299848 100644 --- a/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java +++ b/server/src/test/java/org/opensearch/action/index/IndexResponseTests.java @@ -56,21 +56,21 @@ public class IndexResponseTests extends OpenSearchTestCase { public void testToXContent() { { - IndexResponse indexResponse = new IndexResponse(new ShardId("index", "index_uuid", 0), "type", "id", 3, 17, 5, true); + IndexResponse indexResponse = new IndexResponse(new ShardId("index", "index_uuid", 0), "id", 3, 17, 5, true); String output = Strings.toString(indexResponse); assertEquals( - "{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":5,\"result\":\"created\",\"_shards\":null," + "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":5,\"result\":\"created\",\"_shards\":null," + "\"_seq_no\":3,\"_primary_term\":17}", output ); } { - IndexResponse indexResponse = new IndexResponse(new ShardId("index", "index_uuid", 0), "type", "id", -1, 17, 7, true); + IndexResponse indexResponse = new IndexResponse(new ShardId("index", "index_uuid", 0), "id", -1, 17, 7, true); indexResponse.setForcedRefresh(true); indexResponse.setShardInfo(new ReplicationResponse.ShardInfo(10, 5)); String output = Strings.toString(indexResponse); assertEquals( - "{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":7,\"result\":\"created\"," + "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":7,\"result\":\"created\"," + "\"forced_refresh\":true,\"_shards\":{\"total\":10,\"successful\":5,\"failed\":0}}", output ); @@ -124,7 +124,6 @@ private void doFromXContentTestWithRandomFields(boolean addRandomFields) throws public static void assertDocWriteResponse(DocWriteResponse expected, DocWriteResponse actual) { assertEquals(expected.getIndex(), actual.getIndex()); - assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getSeqNo(), actual.getSeqNo()); assertEquals(expected.getResult(), actual.getResult()); @@ -144,7 +143,6 @@ public static Tuple randomIndexResponse() { String index = randomAlphaOfLength(5); String indexUUid = randomAlphaOfLength(5); int shardId = randomIntBetween(0, 5); - String type = randomAlphaOfLength(5); String id = randomAlphaOfLength(5); long seqNo = randomFrom(SequenceNumbers.UNASSIGNED_SEQ_NO, randomNonNegativeLong(), (long) randomIntBetween(0, 10000)); long primaryTerm = seqNo == SequenceNumbers.UNASSIGNED_SEQ_NO ? 0 : randomIntBetween(1, 10000); @@ -154,19 +152,11 @@ public static Tuple randomIndexResponse() { Tuple shardInfos = RandomObjects.randomShardInfo(random()); - IndexResponse actual = new IndexResponse(new ShardId(index, indexUUid, shardId), type, id, seqNo, primaryTerm, version, created); + IndexResponse actual = new IndexResponse(new ShardId(index, indexUUid, shardId), id, seqNo, primaryTerm, version, created); actual.setForcedRefresh(forcedRefresh); actual.setShardInfo(shardInfos.v1()); - IndexResponse expected = new IndexResponse( - new ShardId(index, INDEX_UUID_NA_VALUE, -1), - type, - id, - seqNo, - primaryTerm, - version, - created - ); + IndexResponse expected = new IndexResponse(new ShardId(index, INDEX_UUID_NA_VALUE, -1), id, seqNo, primaryTerm, version, created); expected.setForcedRefresh(forcedRefresh); expected.setShardInfo(shardInfos.v2()); diff --git a/server/src/test/java/org/opensearch/action/ingest/SimulateExecutionServiceTests.java b/server/src/test/java/org/opensearch/action/ingest/SimulateExecutionServiceTests.java index 74a787244ca42..ff7b0dddb33a3 100644 --- a/server/src/test/java/org/opensearch/action/ingest/SimulateExecutionServiceTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/SimulateExecutionServiceTests.java @@ -352,7 +352,7 @@ public void testAsyncSimulation() throws Exception { int numDocs = randomIntBetween(1, 64); List documents = new ArrayList<>(numDocs); for (int id = 0; id < numDocs; id++) { - documents.add(new IngestDocument("_index", "_type", Integer.toString(id), null, 0L, VersionType.INTERNAL, new HashMap<>())); + documents.add(new IngestDocument("_index", Integer.toString(id), null, 0L, VersionType.INTERNAL, new HashMap<>())); } Processor processor1 = new AbstractProcessor(null, null) { diff --git a/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java b/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java index f732178821b4a..c85c0a01de63e 100644 --- a/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java @@ -86,15 +86,7 @@ public void init() throws IOException { when(ingestService.getProcessorFactories()).thenReturn(registry); } - public void testParseUsingPipelineStoreNoType() throws Exception { - innerTestParseUsingPipelineStore(false); - } - - public void testParseUsingPipelineStoreWithType() throws Exception { - innerTestParseUsingPipelineStore(true); - } - - private void innerTestParseUsingPipelineStore(boolean useExplicitType) throws Exception { + public void testParseUsingPipelineStore(boolean useExplicitType) throws Exception { int numDocs = randomIntBetween(1, 10); Map requestContent = new HashMap<>(); @@ -104,12 +96,8 @@ private void innerTestParseUsingPipelineStore(boolean useExplicitType) throws Ex for (int i = 0; i < numDocs; i++) { Map doc = new HashMap<>(); String index = randomAlphaOfLengthBetween(1, 10); - String type = randomAlphaOfLengthBetween(1, 10); String id = randomAlphaOfLengthBetween(1, 10); doc.put(INDEX.getFieldName(), index); - if (useExplicitType) { - doc.put(TYPE.getFieldName(), type); - } doc.put(ID.getFieldName(), id); String fieldName = randomAlphaOfLengthBetween(1, 10); String fieldValue = randomAlphaOfLengthBetween(1, 10); @@ -117,11 +105,6 @@ private void innerTestParseUsingPipelineStore(boolean useExplicitType) throws Ex docs.add(doc); Map expectedDoc = new HashMap<>(); expectedDoc.put(INDEX.getFieldName(), index); - if (useExplicitType) { - expectedDoc.put(TYPE.getFieldName(), type); - } else { - expectedDoc.put(TYPE.getFieldName(), "_doc"); - } expectedDoc.put(ID.getFieldName(), id); expectedDoc.put(Fields.SOURCE, Collections.singletonMap(fieldName, fieldValue)); expectedDocs.add(expectedDoc); @@ -140,7 +123,6 @@ private void innerTestParseUsingPipelineStore(boolean useExplicitType) throws Ex Map expectedDocument = expectedDocsIterator.next(); Map metadataMap = ingestDocument.extractMetadata(); assertThat(metadataMap.get(INDEX), equalTo(expectedDocument.get(INDEX.getFieldName()))); - assertThat(metadataMap.get(TYPE), equalTo(expectedDocument.get(TYPE.getFieldName()))); assertThat(metadataMap.get(ID), equalTo(expectedDocument.get(ID.getFieldName()))); assertThat(ingestDocument.getSourceAndMetadata(), equalTo(expectedDocument.get(Fields.SOURCE))); } @@ -148,9 +130,6 @@ private void innerTestParseUsingPipelineStore(boolean useExplicitType) throws Ex assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID)); assertThat(actualRequest.getPipeline().getDescription(), nullValue()); assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(1)); - if (useExplicitType) { - assertWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated"); - } } public void testParseWithProvidedPipelineNoType() throws Exception { diff --git a/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java b/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java index 09cb4bd3cf054..380b0628147de 100644 --- a/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java +++ b/server/src/test/java/org/opensearch/action/update/UpdateRequestTests.java @@ -142,7 +142,7 @@ public void setUp() throws Exception { @SuppressWarnings("unchecked") public void testFromXContent() throws Exception { - UpdateRequest request = new UpdateRequest("test", "type", "1"); + UpdateRequest request = new UpdateRequest("test", "1"); // simple script request.fromXContent(createParser(XContentFactory.jsonBuilder().startObject().field("script", "script1").endObject())); Script script = request.script(); @@ -168,7 +168,7 @@ public void testFromXContent() throws Exception { assertThat(params, equalTo(emptyMap())); // script with params - request = new UpdateRequest("test", "type", "1"); + request = new UpdateRequest("test", "1"); request.fromXContent( createParser( XContentFactory.jsonBuilder() @@ -192,7 +192,7 @@ public void testFromXContent() throws Exception { assertThat(params.size(), equalTo(1)); assertThat(params.get("param1").toString(), equalTo("value1")); - request = new UpdateRequest("test", "type", "1"); + request = new UpdateRequest("test", "1"); request.fromXContent( createParser( XContentFactory.jsonBuilder() @@ -217,7 +217,7 @@ public void testFromXContent() throws Exception { assertThat(params.get("param1").toString(), equalTo("value1")); // script with params and upsert - request = new UpdateRequest("test", "type", "1"); + request = new UpdateRequest("test", "1"); request.fromXContent( createParser( XContentFactory.jsonBuilder() @@ -254,7 +254,7 @@ public void testFromXContent() throws Exception { assertThat(upsertDoc.get("field1").toString(), equalTo("value1")); assertThat(((Map) upsertDoc.get("compound")).get("field2").toString(), equalTo("value2")); - request = new UpdateRequest("test", "type", "1"); + request = new UpdateRequest("test", "1"); request.fromXContent( createParser( XContentFactory.jsonBuilder() @@ -288,7 +288,7 @@ public void testFromXContent() throws Exception { assertThat(((Map) upsertDoc.get("compound")).get("field2").toString(), equalTo("value2")); // script with doc - request = new UpdateRequest("test", "type", "1"); + request = new UpdateRequest("test", "1"); request.fromXContent( createParser( XContentFactory.jsonBuilder() @@ -308,13 +308,13 @@ public void testFromXContent() throws Exception { } public void testUnknownFieldParsing() throws Exception { - UpdateRequest request = new UpdateRequest("test", "type", "1"); + UpdateRequest request = new UpdateRequest("test", "1"); XContentParser contentParser = createParser(XContentFactory.jsonBuilder().startObject().field("unknown_field", "test").endObject()); XContentParseException ex = expectThrows(XContentParseException.class, () -> request.fromXContent(contentParser)); assertEquals("[1:2] [UpdateRequest] unknown field [unknown_field]", ex.getMessage()); - UpdateRequest request2 = new UpdateRequest("test", "type", "1"); + UpdateRequest request2 = new UpdateRequest("test", "1"); XContentParser unknownObject = createParser( XContentFactory.jsonBuilder() .startObject() @@ -329,7 +329,7 @@ public void testUnknownFieldParsing() throws Exception { } public void testFetchSourceParsing() throws Exception { - UpdateRequest request = new UpdateRequest("test", "type1", "1"); + UpdateRequest request = new UpdateRequest("test", "1"); request.fromXContent(createParser(XContentFactory.jsonBuilder().startObject().field("_source", true).endObject())); assertThat(request.fetchSource(), notNullValue()); assertThat(request.fetchSource().includes().length, equalTo(0)); @@ -370,12 +370,10 @@ public void testFetchSourceParsing() throws Exception { public void testNowInScript() throws IOException { // We just upsert one document with now() using a script - IndexRequest indexRequest = new IndexRequest("test", "type1", "2").source( - jsonBuilder().startObject().field("foo", "bar").endObject() - ); + IndexRequest indexRequest = new IndexRequest("test").id("2").source(jsonBuilder().startObject().field("foo", "bar").endObject()); { - UpdateRequest updateRequest = new UpdateRequest("test", "type1", "2").upsert(indexRequest) + UpdateRequest updateRequest = new UpdateRequest("test", "2").upsert(indexRequest) .script(mockInlineScript("ctx._source.update_timestamp = ctx._now")) .scriptedUpsert(true); long nowInMillis = randomNonNegativeLong(); @@ -388,7 +386,7 @@ public void testNowInScript() throws IOException { assertEquals(nowInMillis, indexAction.sourceAsMap().get("update_timestamp")); } { - UpdateRequest updateRequest = new UpdateRequest("test", "type1", "2").upsert(indexRequest) + UpdateRequest updateRequest = new UpdateRequest("test", "2").upsert(indexRequest) .script(mockInlineScript("ctx._timestamp = ctx._now")) .scriptedUpsert(true); // We simulate that the document is not existing yet @@ -401,14 +399,13 @@ public void testNowInScript() throws IOException { public void testIndexTimeout() { final GetResult getResult = new GetResult("test", "1", 0, 1, 0, true, new BytesArray("{\"f\":\"v\"}"), null, null); - final UpdateRequest updateRequest = new UpdateRequest("test", "type", "1").script(mockInlineScript("return")) - .timeout(randomTimeValue()); + final UpdateRequest updateRequest = new UpdateRequest("test", "1").script(mockInlineScript("return")).timeout(randomTimeValue()); runTimeoutTest(getResult, updateRequest); } public void testDeleteTimeout() { final GetResult getResult = new GetResult("test", "1", 0, 1, 0, true, new BytesArray("{\"f\":\"v\"}"), null, null); - final UpdateRequest updateRequest = new UpdateRequest("test", "type", "1").script(mockInlineScript("ctx.op = delete")) + final UpdateRequest updateRequest = new UpdateRequest("test", "1").script(mockInlineScript("ctx.op = delete")) .timeout(randomTimeValue()); runTimeoutTest(getResult, updateRequest); } @@ -423,8 +420,8 @@ public void testUpsertTimeout() throws IOException { sourceBuilder.field("f", "v"); } sourceBuilder.endObject(); - final IndexRequest upsert = new IndexRequest("test", "type", "1").source(sourceBuilder); - final UpdateRequest updateRequest = new UpdateRequest("test", "type", "1").upsert(upsert) + final IndexRequest upsert = new IndexRequest("test").id("1").source(sourceBuilder); + final UpdateRequest updateRequest = new UpdateRequest("test", "1").upsert(upsert) .script(mockInlineScript("return")) .timeout(randomTimeValue()); runTimeoutTest(getResult, updateRequest); @@ -514,11 +511,11 @@ public void testToAndFromXContent() throws IOException { } public void testToValidateUpsertRequestAndCAS() { - UpdateRequest updateRequest = new UpdateRequest("index", "type", "id"); + UpdateRequest updateRequest = new UpdateRequest("index", "id"); updateRequest.setIfSeqNo(1L); updateRequest.setIfPrimaryTerm(1L); updateRequest.doc("{}", XContentType.JSON); - updateRequest.upsert(new IndexRequest("index", "type", "id")); + updateRequest.upsert(new IndexRequest("index").id("id")); assertThat( updateRequest.validate().validationErrors(), contains("upsert requests don't support `if_seq_no` and `if_primary_term`") @@ -526,15 +523,15 @@ public void testToValidateUpsertRequestAndCAS() { } public void testToValidateUpsertRequestWithVersion() { - UpdateRequest updateRequest = new UpdateRequest("index", "type", "id"); + UpdateRequest updateRequest = new UpdateRequest("index", "id"); updateRequest.doc("{}", XContentType.JSON); - updateRequest.upsert(new IndexRequest("index", "type", "1").version(1L)); + updateRequest.upsert(new IndexRequest("index").id("1").version(1L)); assertThat(updateRequest.validate().validationErrors(), contains("can't provide version in upsert request")); } public void testValidate() { { - UpdateRequest request = new UpdateRequest("index", "type", "id"); + UpdateRequest request = new UpdateRequest("index", "id"); request.doc("{}", XContentType.JSON); ActionRequestValidationException validate = request.validate(); @@ -542,27 +539,18 @@ public void testValidate() { } { // Null types are defaulted to "_doc" - UpdateRequest request = new UpdateRequest("index", null, randomBoolean() ? "" : null); + UpdateRequest request = new UpdateRequest("index", null); request.doc("{}", XContentType.JSON); ActionRequestValidationException validate = request.validate(); assertThat(validate, not(nullValue())); assertThat(validate.validationErrors(), hasItems("id is missing")); } - { - // Non-null types are accepted but fail validation - UpdateRequest request = new UpdateRequest("index", "", randomBoolean() ? "" : null); - request.doc("{}", XContentType.JSON); - ActionRequestValidationException validate = request.validate(); - - assertThat(validate, not(nullValue())); - assertThat(validate.validationErrors(), hasItems("type is missing", "id is missing")); - } } public void testRoutingExtraction() throws Exception { GetResult getResult = new GetResult("test", "1", UNASSIGNED_SEQ_NO, 0, 0, false, null, null, null); - IndexRequest indexRequest = new IndexRequest("test", "type", "1"); + IndexRequest indexRequest = new IndexRequest("test").id("1"); // There is no routing and parent because the document doesn't exist assertNull(UpdateHelper.calculateRouting(getResult, null)); @@ -590,7 +578,7 @@ public void testNoopDetection() throws Exception { ShardId shardId = new ShardId("test", "", 0); GetResult getResult = new GetResult("test", "1", 0, 1, 0, true, new BytesArray("{\"body\": \"foo\"}"), null, null); - UpdateRequest request = new UpdateRequest("test", "type1", "1").fromXContent( + UpdateRequest request = new UpdateRequest("test", "1").fromXContent( createParser(JsonXContent.jsonXContent, new BytesArray("{\"doc\": {\"body\": \"foo\"}}")) ); @@ -606,7 +594,7 @@ public void testNoopDetection() throws Exception { assertThat(result.updatedSourceAsMap().get("body").toString(), equalTo("foo")); // Change the request to be a different doc - request = new UpdateRequest("test", "type1", "1").fromXContent( + request = new UpdateRequest("test", "1").fromXContent( createParser(JsonXContent.jsonXContent, new BytesArray("{\"doc\": {\"body\": \"bar\"}}")) ); result = updateHelper.prepareUpdateIndexRequest(shardId, request, getResult, true); @@ -621,7 +609,7 @@ public void testUpdateScript() throws Exception { ShardId shardId = new ShardId("test", "", 0); GetResult getResult = new GetResult("test", "1", 0, 1, 0, true, new BytesArray("{\"body\": \"bar\"}"), null, null); - UpdateRequest request = new UpdateRequest("test", "type1", "1").script(mockInlineScript("ctx._source.body = \"foo\"")); + UpdateRequest request = new UpdateRequest("test", "1").script(mockInlineScript("ctx._source.body = \"foo\"")); UpdateHelper.Result result = updateHelper.prepareUpdateScriptRequest( shardId, @@ -635,7 +623,7 @@ public void testUpdateScript() throws Exception { assertThat(result.updatedSourceAsMap().get("body").toString(), equalTo("foo")); // Now where the script changes the op to "delete" - request = new UpdateRequest("test", "type1", "1").script(mockInlineScript("ctx.op = delete")); + request = new UpdateRequest("test", "1").script(mockInlineScript("ctx.op = delete")); result = updateHelper.prepareUpdateScriptRequest(shardId, request, getResult, OpenSearchTestCase::randomNonNegativeLong); @@ -645,9 +633,9 @@ public void testUpdateScript() throws Exception { // We treat everything else as a No-op boolean goodNoop = randomBoolean(); if (goodNoop) { - request = new UpdateRequest("test", "type1", "1").script(mockInlineScript("ctx.op = none")); + request = new UpdateRequest("test", "1").script(mockInlineScript("ctx.op = none")); } else { - request = new UpdateRequest("test", "type1", "1").script(mockInlineScript("ctx.op = bad")); + request = new UpdateRequest("test", "1").script(mockInlineScript("ctx.op = bad")); } result = updateHelper.prepareUpdateScriptRequest(shardId, request, getResult, OpenSearchTestCase::randomNonNegativeLong); @@ -657,23 +645,23 @@ public void testUpdateScript() throws Exception { } public void testToString() throws IOException { - UpdateRequest request = new UpdateRequest("test", "type1", "1").script(mockInlineScript("ctx._source.body = \"foo\"")); + UpdateRequest request = new UpdateRequest("test", "1").script(mockInlineScript("ctx._source.body = \"foo\"")); assertThat( request.toString(), equalTo( - "update {[test][type1][1], doc_as_upsert[false], " + "update {[test][1], doc_as_upsert[false], " + "script[Script{type=inline, lang='mock', idOrCode='ctx._source.body = \"foo\"', options={}, params={}}], " + "scripted_upsert[false], detect_noop[true]}" ) ); - request = new UpdateRequest("test", "type1", "1").fromXContent( + request = new UpdateRequest("test", "1").fromXContent( createParser(JsonXContent.jsonXContent, new BytesArray("{\"doc\": {\"body\": \"bar\"}}")) ); assertThat( request.toString(), equalTo( - "update {[test][type1][1], doc_as_upsert[false], " - + "doc[index {[null][_doc][null], source[{\"body\":\"bar\"}]}], scripted_upsert[false], detect_noop[true]}" + "update {[test][1], doc_as_upsert[false], " + + "doc[index {[null][null], source[{\"body\":\"bar\"}]}], scripted_upsert[false], detect_noop[true]}" ) ); } diff --git a/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java b/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java index 783c0ec33d63a..ba0abd6c8e349 100644 --- a/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java +++ b/server/src/test/java/org/opensearch/action/update/UpdateResponseTests.java @@ -45,7 +45,6 @@ import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.get.GetResult; import org.opensearch.index.get.GetResultTests; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.seqno.SequenceNumbers; import org.opensearch.index.shard.ShardId; import org.opensearch.test.OpenSearchTestCase; @@ -69,10 +68,10 @@ public class UpdateResponseTests extends OpenSearchTestCase { public void testToXContent() throws IOException { { - UpdateResponse updateResponse = new UpdateResponse(new ShardId("index", "index_uuid", 0), "type", "id", -2, 0, 0, NOT_FOUND); + UpdateResponse updateResponse = new UpdateResponse(new ShardId("index", "index_uuid", 0), "id", -2, 0, 0, NOT_FOUND); String output = Strings.toString(updateResponse); assertEquals( - "{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_version\":0,\"result\":\"not_found\"," + "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":0,\"result\":\"not_found\"," + "\"_shards\":{\"total\":0,\"successful\":0,\"failed\":0}}", output ); @@ -81,7 +80,6 @@ public void testToXContent() throws IOException { UpdateResponse updateResponse = new UpdateResponse( new ReplicationResponse.ShardInfo(10, 6), new ShardId("index", "index_uuid", 1), - "type", "id", 3, 17, @@ -90,7 +88,7 @@ public void testToXContent() throws IOException { ); String output = Strings.toString(updateResponse); assertEquals( - "{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_version\":1,\"result\":\"deleted\"," + "{\"_index\":\"index\",\"_id\":\"id\",\"_version\":1,\"result\":\"deleted\"," + "\"_shards\":{\"total\":10,\"successful\":6,\"failed\":0},\"_seq_no\":3,\"_primary_term\":17}", output ); @@ -104,7 +102,6 @@ public void testToXContent() throws IOException { UpdateResponse updateResponse = new UpdateResponse( new ReplicationResponse.ShardInfo(3, 2), new ShardId("books", "books_uuid", 2), - "book", "1", 7, 17, @@ -115,7 +112,7 @@ public void testToXContent() throws IOException { String output = Strings.toString(updateResponse); assertEquals( - "{\"_index\":\"books\",\"_type\":\"_doc\",\"_id\":\"1\",\"_version\":2,\"result\":\"updated\"," + "{\"_index\":\"books\",\"_id\":\"1\",\"_version\":2,\"result\":\"updated\"," + "\"_shards\":{\"total\":3,\"successful\":2,\"failed\":0},\"_seq_no\":7,\"_primary_term\":17,\"get\":{" + "\"_seq_no\":0,\"_primary_term\":1,\"found\":true," + "\"_source\":{\"title\":\"Book title\",\"isbn\":\"ABC-123\"},\"fields\":{\"isbn\":[\"ABC-123\"],\"title\":[\"Book " @@ -211,29 +208,11 @@ public static Tuple randomUpdateResponse(XConten if (seqNo != SequenceNumbers.UNASSIGNED_SEQ_NO) { Tuple shardInfos = RandomObjects.randomShardInfo(random()); - actual = new UpdateResponse( - shardInfos.v1(), - actualShardId, - MapperService.SINGLE_MAPPING_NAME, - id, - seqNo, - primaryTerm, - version, - result - ); - expected = new UpdateResponse( - shardInfos.v2(), - expectedShardId, - MapperService.SINGLE_MAPPING_NAME, - id, - seqNo, - primaryTerm, - version, - result - ); + actual = new UpdateResponse(shardInfos.v1(), actualShardId, id, seqNo, primaryTerm, version, result); + expected = new UpdateResponse(shardInfos.v2(), expectedShardId, id, seqNo, primaryTerm, version, result); } else { - actual = new UpdateResponse(actualShardId, MapperService.SINGLE_MAPPING_NAME, id, seqNo, primaryTerm, version, result); - expected = new UpdateResponse(expectedShardId, MapperService.SINGLE_MAPPING_NAME, id, seqNo, primaryTerm, version, result); + actual = new UpdateResponse(actualShardId, id, seqNo, primaryTerm, version, result); + expected = new UpdateResponse(expectedShardId, id, seqNo, primaryTerm, version, result); } if (actualGetResult.isExists()) { diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexNameExpressionResolverTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexNameExpressionResolverTests.java index 2a18fed2d68e7..e736e27e5aa44 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -1776,7 +1776,7 @@ public void testConcreteWriteIndexWithNoWriteIndexWithSingleIndex() { assertArrayEquals(new String[] { "test-alias" }, strings); DocWriteRequest request = randomFrom( new IndexRequest("test-alias"), - new UpdateRequest("test-alias", "_type", "_id"), + new UpdateRequest("test-alias", "_id"), new DeleteRequest("test-alias") ); IllegalArgumentException exception = expectThrows( @@ -1811,7 +1811,7 @@ public void testConcreteWriteIndexWithNoWriteIndexWithMultipleIndices() { assertArrayEquals(new String[] { "test-alias" }, strings); DocWriteRequest request = randomFrom( new IndexRequest("test-alias"), - new UpdateRequest("test-alias", "_type", "_id"), + new UpdateRequest("test-alias", "_id"), new DeleteRequest("test-alias") ); IllegalArgumentException exception = expectThrows( diff --git a/server/src/test/java/org/opensearch/index/IndexingPressureServiceTests.java b/server/src/test/java/org/opensearch/index/IndexingPressureServiceTests.java index 531866dd82ee9..22d185643018a 100644 --- a/server/src/test/java/org/opensearch/index/IndexingPressureServiceTests.java +++ b/server/src/test/java/org/opensearch/index/IndexingPressureServiceTests.java @@ -51,11 +51,7 @@ public void testCoordinatingOperationForShardIndexingPressure() { Index index = new Index("IndexName", "UUID"); ShardId shardId = new ShardId(index, 0); BulkItemRequest[] items = new BulkItemRequest[1]; - DocWriteRequest writeRequest = new IndexRequest("index", "_doc", "id").source( - Requests.INDEX_CONTENT_TYPE, - "foo", - "bar" - ); + DocWriteRequest writeRequest = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar"); items[0] = new BulkItemRequest(0, writeRequest); BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, WriteRequest.RefreshPolicy.NONE, items); Releasable releasable = service.markCoordinatingOperationStarted(shardId, bulkShardRequest::ramBytesUsed, false); diff --git a/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java b/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java index ac999d34785ea..6fe277ad2751b 100644 --- a/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java +++ b/server/src/test/java/org/opensearch/index/reindex/ReindexRequestTests.java @@ -112,9 +112,6 @@ protected ReindexRequest createTestInstance() { if (randomBoolean()) { reindexRequest.setSourceBatchSize(randomInt(100)); } - if (randomBoolean()) { - reindexRequest.setDestDocType("type"); - } if (randomBoolean()) { reindexRequest.setDestOpType("create"); } @@ -160,7 +157,6 @@ protected void assertEqualInstances(ReindexRequest expectedInstance, ReindexRequ assertEquals(expectedInstance.getDestination().getPipeline(), newInstance.getDestination().getPipeline()); assertEquals(expectedInstance.getDestination().routing(), newInstance.getDestination().routing()); assertEquals(expectedInstance.getDestination().opType(), newInstance.getDestination().opType()); - assertEquals(expectedInstance.getDestination().type(), newInstance.getDestination().type()); } public void testReindexFromRemoteDoesNotSupportSearchQuery() { diff --git a/server/src/test/java/org/opensearch/index/replication/IndexLevelReplicationTests.java b/server/src/test/java/org/opensearch/index/replication/IndexLevelReplicationTests.java index 2167bc7c2c024..6e2efe56a69d7 100644 --- a/server/src/test/java/org/opensearch/index/replication/IndexLevelReplicationTests.java +++ b/server/src/test/java/org/opensearch/index/replication/IndexLevelReplicationTests.java @@ -173,7 +173,7 @@ public void cleanFiles( public void testRetryAppendOnlyAfterRecovering() throws Exception { try (ReplicationGroup shards = createGroup(0)) { shards.startAll(); - final IndexRequest originalRequest = new IndexRequest(index.getName(), "type").source("{}", XContentType.JSON); + final IndexRequest originalRequest = new IndexRequest(index.getName()).source("{}", XContentType.JSON); originalRequest.process(Version.CURRENT, null, index.getName()); final IndexRequest retryRequest = copyIndexRequest(originalRequest); retryRequest.onRetry(); @@ -214,7 +214,7 @@ public IndexResult index(Index op) throws IOException { }) { shards.startAll(); Thread thread = new Thread(() -> { - IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}", XContentType.JSON); + IndexRequest indexRequest = new IndexRequest(index.getName()).source("{}", XContentType.JSON); try { shards.index(indexRequest); } catch (Exception e) { @@ -244,7 +244,7 @@ public void prepareForTranslogOperations(int totalTranslogOps, ActionListener replicas = shards.getReplicas(); IndexShard replica1 = replicas.get(0); - IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "1").source("{ \"f\": \"1\"}", XContentType.JSON); + IndexRequest indexRequest = new IndexRequest(index.getName()).id("1").source("{ \"f\": \"1\"}", XContentType.JSON); logger.info("--> isolated replica " + replica1.routingEntry()); BulkShardRequest replicationRequest = indexOnPrimary(indexRequest, shards.getPrimary()); for (int i = 1; i < replicas.size(); i++) { @@ -332,7 +332,7 @@ public void testConflictingOpsOnReplica() throws Exception { logger.info("--> promoting replica to primary " + replica1.routingEntry()); shards.promoteReplicaToPrimary(replica1).get(); - indexRequest = new IndexRequest(index.getName(), "type", "1").source("{ \"f\": \"2\"}", XContentType.JSON); + indexRequest = new IndexRequest(index.getName()).id("1").source("{ \"f\": \"2\"}", XContentType.JSON); shards.index(indexRequest); shards.refresh("test"); for (IndexShard shard : shards) { @@ -362,7 +362,7 @@ public void testReplicaTermIncrementWithConcurrentPrimaryPromotion() throws Exce assertEquals(primaryPrimaryTerm, replica2.getPendingPrimaryTerm()); - IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "1").source("{ \"f\": \"1\"}", XContentType.JSON); + IndexRequest indexRequest = new IndexRequest(index.getName()).id("1").source("{ \"f\": \"1\"}", XContentType.JSON); BulkShardRequest replicationRequest = indexOnPrimary(indexRequest, replica1); CyclicBarrier barrier = new CyclicBarrier(2); @@ -405,7 +405,7 @@ public void testReplicaOperationWithConcurrentPrimaryPromotion() throws Exceptio try (ReplicationGroup shards = new ReplicationGroup(buildIndexMetadata(1, mappings))) { shards.startAll(); long primaryPrimaryTerm = shards.getPrimary().getPendingPrimaryTerm(); - IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "1").source("{ \"f\": \"1\"}", XContentType.JSON); + IndexRequest indexRequest = new IndexRequest(index.getName()).id("1").source("{ \"f\": \"1\"}", XContentType.JSON); BulkShardRequest replicationRequest = indexOnPrimary(indexRequest, shards.getPrimary()); List replicas = shards.getReplicas(); @@ -485,7 +485,7 @@ protected EngineFactory getEngineFactory(ShardRouting routing) { shards.startPrimary(); long primaryTerm = shards.getPrimary().getPendingPrimaryTerm(); List expectedTranslogOps = new ArrayList<>(); - BulkItemResponse indexResp = shards.index(new IndexRequest(index.getName(), "type", "1").source("{}", XContentType.JSON)); + BulkItemResponse indexResp = shards.index(new IndexRequest(index.getName()).id("1").source("{}", XContentType.JSON)); assertThat(indexResp.isFailed(), equalTo(true)); assertThat(indexResp.getFailure().getCause(), equalTo(indexException)); expectedTranslogOps.add(new Translog.NoOp(0, primaryTerm, indexException.toString())); @@ -540,9 +540,7 @@ protected EngineFactory getEngineFactory(ShardRouting routing) { public void testRequestFailureReplication() throws Exception { try (ReplicationGroup shards = createGroup(0)) { shards.startAll(); - BulkItemResponse response = shards.index( - new IndexRequest(index.getName(), "type", "1").source("{}", XContentType.JSON).version(2) - ); + BulkItemResponse response = shards.index(new IndexRequest(index.getName()).id("1").source("{}", XContentType.JSON).version(2)); assertTrue(response.isFailed()); assertThat(response.getFailure().getCause(), instanceOf(VersionConflictEngineException.class)); shards.assertAllEqual(0); @@ -560,7 +558,7 @@ public void testRequestFailureReplication() throws Exception { shards.addReplica(); } shards.startReplicas(nReplica); - response = shards.index(new IndexRequest(index.getName(), "type", "1").source("{}", XContentType.JSON).version(2)); + response = shards.index(new IndexRequest(index.getName()).id("1").source("{}", XContentType.JSON).version(2)); assertTrue(response.isFailed()); assertThat(response.getFailure().getCause(), instanceOf(VersionConflictEngineException.class)); shards.assertAllEqual(0); @@ -593,7 +591,7 @@ public void testSeqNoCollision() throws Exception { shards.syncGlobalCheckpoint(); logger.info("--> Isolate replica1"); - IndexRequest indexDoc1 = new IndexRequest(index.getName(), "type", "d1").source("{}", XContentType.JSON); + IndexRequest indexDoc1 = new IndexRequest(index.getName()).id("d1").source("{}", XContentType.JSON); BulkShardRequest replicationRequest = indexOnPrimary(indexDoc1, shards.getPrimary()); indexOnReplica(replicationRequest, shards, replica2); @@ -613,7 +611,7 @@ public void testSeqNoCollision() throws Exception { } logger.info("--> Promote replica1 as the primary"); shards.promoteReplicaToPrimary(replica1).get(); // wait until resync completed. - shards.index(new IndexRequest(index.getName(), "type", "d2").source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id("d2").source("{}", XContentType.JSON)); final Translog.Operation op2; try (Translog.Snapshot snapshot = getTranslog(replica2).newSnapshot()) { assertThat(snapshot.totalOperations(), equalTo(1)); @@ -663,10 +661,10 @@ public void testLateDeliveryAfterGCTriggeredOnReplica() throws Exception { updateGCDeleteCycle(replica, gcInterval); final BulkShardRequest indexRequest = indexOnPrimary( - new IndexRequest(index.getName(), "type", "d1").source("{}", XContentType.JSON), + new IndexRequest(index.getName()).id("d1").source("{}", XContentType.JSON), primary ); - final BulkShardRequest deleteRequest = deleteOnPrimary(new DeleteRequest(index.getName(), "type", "d1"), primary); + final BulkShardRequest deleteRequest = deleteOnPrimary(new DeleteRequest(index.getName()).id("d1"), primary); deleteOnReplica(deleteRequest, shards, replica); // delete arrives on replica first. final long deleteTimestamp = threadPool.relativeTimeInMillis(); replica.refresh("test"); @@ -700,11 +698,11 @@ public void testOutOfOrderDeliveryForAppendOnlyOperations() throws Exception { final IndexShard replica = shards.getReplicas().get(0); // Append-only request - without id final BulkShardRequest indexRequest = indexOnPrimary( - new IndexRequest(index.getName(), "type", null).source("{}", XContentType.JSON), + new IndexRequest(index.getName()).id(null).source("{}", XContentType.JSON), primary ); final String docId = Iterables.get(getShardDocUIDs(primary), 0); - final BulkShardRequest deleteRequest = deleteOnPrimary(new DeleteRequest(index.getName(), "type", docId), primary); + final BulkShardRequest deleteRequest = deleteOnPrimary(new DeleteRequest(index.getName()).id(docId), primary); deleteOnReplica(deleteRequest, shards, replica); indexOnReplica(indexRequest, shards, replica); shards.assertAllEqual(0); @@ -720,12 +718,12 @@ public void testIndexingOptimizationUsingSequenceNumbers() throws Exception { for (int i = 0; i < numDocs; i++) { String id = Integer.toString(randomIntBetween(1, 100)); if (randomBoolean()) { - group.index(new IndexRequest(index.getName(), "type", id).source("{}", XContentType.JSON)); + group.index(new IndexRequest(index.getName()).id(id).source("{}", XContentType.JSON)); if (liveDocs.add(id) == false) { versionLookups++; } } else { - group.delete(new DeleteRequest(index.getName(), "type", id)); + group.delete(new DeleteRequest(index.getName(), id)); liveDocs.remove(id); versionLookups++; } diff --git a/server/src/test/java/org/opensearch/index/replication/RecoveryDuringReplicationTests.java b/server/src/test/java/org/opensearch/index/replication/RecoveryDuringReplicationTests.java index c59d4849feffb..cccb2f470195b 100644 --- a/server/src/test/java/org/opensearch/index/replication/RecoveryDuringReplicationTests.java +++ b/server/src/test/java/org/opensearch/index/replication/RecoveryDuringReplicationTests.java @@ -143,7 +143,7 @@ public void testRecoveryToReplicaThatReceivedExtraDocument() throws Exception { shards.startAll(); final int docs = randomIntBetween(0, 16); for (int i = 0; i < docs; i++) { - shards.index(new IndexRequest("index", "type", Integer.toString(i)).source("{}", XContentType.JSON)); + shards.index(new IndexRequest("index").id(Integer.toString(i)).source("{}", XContentType.JSON)); } shards.flush(); @@ -210,10 +210,7 @@ public void testRecoveryAfterPrimaryPromotion() throws Exception { final int rollbackDocs = randomIntBetween(1, 5); logger.info("--> indexing {} rollback docs", rollbackDocs); for (int i = 0; i < rollbackDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "rollback_" + i).source( - "{}", - XContentType.JSON - ); + final IndexRequest indexRequest = new IndexRequest(index.getName()).id("rollback_" + i).source("{}", XContentType.JSON); final BulkShardRequest bulkShardRequest = indexOnPrimary(indexRequest, oldPrimary); indexOnReplica(bulkShardRequest, shards, replica); } @@ -331,7 +328,7 @@ public void testReplicaRollbackStaleDocumentsInPeerRecovery() throws Exception { int staleDocs = scaledRandomIntBetween(1, 10); logger.info("--> indexing {} stale docs", staleDocs); for (int i = 0; i < staleDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "stale_" + i).source("{}", XContentType.JSON); + final IndexRequest indexRequest = new IndexRequest(index.getName()).id("stale_" + i).source("{}", XContentType.JSON); final BulkShardRequest bulkShardRequest = indexOnPrimary(indexRequest, oldPrimary); indexOnReplica(bulkShardRequest, shards, replica); } @@ -370,10 +367,8 @@ public void testResyncAfterPrimaryPromotion() throws Exception { int initialDocs = randomInt(10); for (int i = 0; i < initialDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "initial_doc_" + i).source( - "{ \"f\": \"normal\"}", - XContentType.JSON - ); + final IndexRequest indexRequest = new IndexRequest(index.getName()).id("initial_doc_" + i) + .source("{ \"f\": \"normal\"}", XContentType.JSON); shards.index(indexRequest); } @@ -390,10 +385,8 @@ public void testResyncAfterPrimaryPromotion() throws Exception { final int extraDocs = randomInt(5); logger.info("--> indexing {} extra docs", extraDocs); for (int i = 0; i < extraDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "extra_doc_" + i).source( - "{ \"f\": \"normal\"}", - XContentType.JSON - ); + final IndexRequest indexRequest = new IndexRequest(index.getName()).id("extra_doc_" + i) + .source("{ \"f\": \"normal\"}", XContentType.JSON); final BulkShardRequest bulkShardRequest = indexOnPrimary(indexRequest, oldPrimary); indexOnReplica(bulkShardRequest, shards, newPrimary); } @@ -401,10 +394,8 @@ public void testResyncAfterPrimaryPromotion() throws Exception { final int extraDocsToBeTrimmed = randomIntBetween(0, 10); logger.info("--> indexing {} extra docs to be trimmed", extraDocsToBeTrimmed); for (int i = 0; i < extraDocsToBeTrimmed; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "extra_trimmed_" + i).source( - "{ \"f\": \"trimmed\"}", - XContentType.JSON - ); + final IndexRequest indexRequest = new IndexRequest(index.getName()).id("extra_trimmed_" + i) + .source("{ \"f\": \"trimmed\"}", XContentType.JSON); final BulkShardRequest bulkShardRequest = indexOnPrimary(indexRequest, oldPrimary); // have to replicate to another replica != newPrimary one - the subject to trim indexOnReplica(bulkShardRequest, shards, justReplica); @@ -472,7 +463,7 @@ protected EngineFactory getEngineFactory(ShardRouting routing) { final String id = "pending_" + i; threadPool.generic().submit(() -> { try { - shards.index(new IndexRequest(index.getName(), "type", id).source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id(id).source("{}", XContentType.JSON)); } catch (Exception e) { throw new AssertionError(e); } finally { @@ -563,7 +554,7 @@ public void indexTranslogOperations( replicaEngineFactory.latchIndexers(1); threadPool.generic().submit(() -> { try { - shards.index(new IndexRequest(index.getName(), "type", "pending").source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id("pending").source("{}", XContentType.JSON)); } catch (final Exception e) { throw new RuntimeException(e); } finally { @@ -575,7 +566,7 @@ public void indexTranslogOperations( replicaEngineFactory.awaitIndexersLatch(); // unblock indexing for the next doc replicaEngineFactory.allowIndexing(); - shards.index(new IndexRequest(index.getName(), "type", "completed").source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id("completed").source("{}", XContentType.JSON)); pendingDocActiveWithExtraDocIndexed.countDown(); } catch (final Exception e) { throw new AssertionError(e); @@ -615,7 +606,7 @@ public void indexTranslogOperations( // wait for the translog phase to complete and the recovery to block global checkpoint advancement assertBusy(() -> assertTrue(shards.getPrimary().pendingInSync())); { - shards.index(new IndexRequest(index.getName(), "type", "last").source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id("last").source("{}", XContentType.JSON)); final long expectedDocs = docs + 3L; assertThat(shards.getPrimary().getLocalCheckpoint(), equalTo(expectedDocs - 1)); // recovery is now in the process of being completed, therefore the global checkpoint can not have advanced on the primary @@ -650,7 +641,7 @@ public void testTransferMaxSeenAutoIdTimestampOnResync() throws Exception { long maxTimestampOnReplica2 = -1; List replicationRequests = new ArrayList<>(); for (int numDocs = between(1, 10), i = 0; i < numDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}", XContentType.JSON); + final IndexRequest indexRequest = new IndexRequest(index.getName()).source("{}", XContentType.JSON); indexRequest.process(Version.CURRENT, null, index.getName()); final IndexRequest copyRequest; if (randomBoolean()) { @@ -708,13 +699,13 @@ public void testAddNewReplicas() throws Exception { int nextId = docId.incrementAndGet(); if (appendOnly) { String id = randomBoolean() ? Integer.toString(nextId) : null; - shards.index(new IndexRequest(index.getName(), "type", id).source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id(id).source("{}", XContentType.JSON)); } else if (frequently()) { String id = Integer.toString(frequently() ? nextId : between(0, nextId)); - shards.index(new IndexRequest(index.getName(), "type", id).source("{}", XContentType.JSON)); + shards.index(new IndexRequest(index.getName()).id(id).source("{}", XContentType.JSON)); } else { String id = Integer.toString(between(0, nextId)); - shards.delete(new DeleteRequest(index.getName(), "type", id)); + shards.delete(new DeleteRequest(index.getName()).id(id)); } if (randomInt(100) < 10) { shards.getPrimary().flush(new FlushRequest()); @@ -749,7 +740,7 @@ public void testRollbackOnPromotion() throws Exception { int inFlightOps = scaledRandomIntBetween(10, 200); for (int i = 0; i < inFlightOps; i++) { String id = "extra-" + i; - IndexRequest primaryRequest = new IndexRequest(index.getName(), "type", id).source("{}", XContentType.JSON); + IndexRequest primaryRequest = new IndexRequest(index.getName()).id(id).source("{}", XContentType.JSON); BulkShardRequest replicationRequest = indexOnPrimary(primaryRequest, shards.getPrimary()); for (IndexShard replica : shards.getReplicas()) { if (randomBoolean()) { diff --git a/server/src/test/java/org/opensearch/indices/recovery/RecoveryTests.java b/server/src/test/java/org/opensearch/indices/recovery/RecoveryTests.java index 0e6b959ee46f9..54f4a22f3a577 100644 --- a/server/src/test/java/org/opensearch/indices/recovery/RecoveryTests.java +++ b/server/src/test/java/org/opensearch/indices/recovery/RecoveryTests.java @@ -486,7 +486,7 @@ public void testRecoveryTrimsLocalTranslog() throws Exception { } int inflightDocs = scaledRandomIntBetween(1, 100); for (int i = 0; i < inflightDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "extra_" + i).source("{}", XContentType.JSON); + final IndexRequest indexRequest = new IndexRequest(index.getName()).id("extra_" + i).source("{}", XContentType.JSON); final BulkShardRequest bulkShardRequest = indexOnPrimary(indexRequest, oldPrimary); for (IndexShard replica : randomSubsetOf(shards.getReplicas())) { indexOnReplica(bulkShardRequest, shards, replica); diff --git a/server/src/test/java/org/opensearch/ingest/IngestDocumentTests.java b/server/src/test/java/org/opensearch/ingest/IngestDocumentTests.java index 2c4bc5061d822..a6ea02a5423c4 100644 --- a/server/src/test/java/org/opensearch/ingest/IngestDocumentTests.java +++ b/server/src/test/java/org/opensearch/ingest/IngestDocumentTests.java @@ -92,7 +92,7 @@ public void setTestIngestDocument() { list2.add("bar"); list2.add("baz"); document.put("list2", list2); - ingestDocument = new IngestDocument("index", "type", "id", null, null, null, document); + ingestDocument = new IngestDocument("index", "id", null, null, null, document); } public void testSimpleGetFieldValue() { @@ -101,7 +101,6 @@ public void testSimpleGetFieldValue() { assertThat(ingestDocument.getFieldValue("_source.foo", String.class), equalTo("bar")); assertThat(ingestDocument.getFieldValue("_source.int", Integer.class), equalTo(123)); assertThat(ingestDocument.getFieldValue("_index", String.class), equalTo("index")); - assertThat(ingestDocument.getFieldValue("_type", String.class), equalTo("type")); assertThat(ingestDocument.getFieldValue("_id", String.class), equalTo("id")); assertThat( ingestDocument.getFieldValue("_ingest.timestamp", ZonedDateTime.class), @@ -238,7 +237,6 @@ public void testGetFieldValueEmpty() { public void testHasField() { assertTrue(ingestDocument.hasField("fizz")); assertTrue(ingestDocument.hasField("_index")); - assertTrue(ingestDocument.hasField("_type")); assertTrue(ingestDocument.hasField("_id")); assertTrue(ingestDocument.hasField("_source.fizz")); assertTrue(ingestDocument.hasField("_ingest.timestamp")); @@ -808,23 +806,23 @@ public void testSetFieldValueEmptyName() { public void testRemoveField() { ingestDocument.removeField("foo"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(7)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("foo"), equalTo(false)); ingestDocument.removeField("_index"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(7)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(6)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("_index"), equalTo(false)); ingestDocument.removeField("_source.fizz"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(6)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(5)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("fizz"), equalTo(false)); assertThat(ingestDocument.getIngestMetadata().size(), equalTo(1)); ingestDocument.removeField("_ingest.timestamp"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(6)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(5)); assertThat(ingestDocument.getIngestMetadata().size(), equalTo(0)); } public void testRemoveInnerField() { ingestDocument.removeField("fizz.buzz"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(9)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); assertThat(ingestDocument.getSourceAndMetadata().get("fizz"), instanceOf(Map.class)); @SuppressWarnings("unchecked") Map map = (Map) ingestDocument.getSourceAndMetadata().get("fizz"); @@ -833,17 +831,17 @@ public void testRemoveInnerField() { ingestDocument.removeField("fizz.foo_null"); assertThat(map.size(), equalTo(2)); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(9)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("fizz"), equalTo(true)); ingestDocument.removeField("fizz.1"); assertThat(map.size(), equalTo(1)); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(9)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("fizz"), equalTo(true)); ingestDocument.removeField("fizz.list"); assertThat(map.size(), equalTo(0)); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(9)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("fizz"), equalTo(true)); } @@ -879,7 +877,7 @@ public void testRemoveSourceObject() { public void testRemoveIngestObject() { ingestDocument.removeField("_ingest"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(7)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("_ingest"), equalTo(false)); } @@ -901,7 +899,7 @@ public void testRemoveEmptyPathAfterStrippingOutPrefix() { public void testListRemoveField() { ingestDocument.removeField("list.0.field"); - assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(9)); + assertThat(ingestDocument.getSourceAndMetadata().size(), equalTo(8)); assertThat(ingestDocument.getSourceAndMetadata().containsKey("list"), equalTo(true)); Object object = ingestDocument.getSourceAndMetadata().get("list"); assertThat(object, instanceOf(List.class)); diff --git a/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java b/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java index 544fa7bc09d8f..fcd15e85979f7 100644 --- a/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java +++ b/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java @@ -181,7 +181,8 @@ public void testExecuteIndexPipelineDoesNotExist() { Collections.singletonList(DUMMY_PLUGIN), client ); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); @@ -729,13 +730,12 @@ public String getType() { ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); final SetOnce failure = new SetOnce<>(); BulkRequest bulkRequest = new BulkRequest(); - final IndexRequest indexRequest1 = new IndexRequest("_index", "_type", "_id1").source(emptyMap()) + final IndexRequest indexRequest1 = new IndexRequest("_index").id("_id1") + .source(emptyMap()) .setPipeline("_none") .setFinalPipeline("_none"); bulkRequest.add(indexRequest1); - IndexRequest indexRequest2 = new IndexRequest("_index", "_type", "_id2").source(emptyMap()) - .setPipeline(id) - .setFinalPipeline("_none"); + IndexRequest indexRequest2 = new IndexRequest("_index").id("_id2").source(emptyMap()).setPipeline(id).setFinalPipeline("_none"); bulkRequest.add(indexRequest2); final BiConsumer failureHandler = (slot, e) -> { @@ -778,15 +778,15 @@ public void testExecuteBulkPipelineDoesNotExist() { BulkRequest bulkRequest = new BulkRequest(); - IndexRequest indexRequest1 = new IndexRequest("_index", "_type", "_id1").source(emptyMap()) + IndexRequest indexRequest1 = new IndexRequest("_index").id("_id1") + .source(emptyMap()) .setPipeline("_none") .setFinalPipeline("_none"); bulkRequest.add(indexRequest1); - IndexRequest indexRequest2 = new IndexRequest("_index", "_type", "_id2").source(emptyMap()) - .setPipeline("_id") - .setFinalPipeline("_none"); + IndexRequest indexRequest2 = new IndexRequest("_index").id("_id2").source(emptyMap()).setPipeline("_id").setFinalPipeline("_none"); bulkRequest.add(indexRequest2); - IndexRequest indexRequest3 = new IndexRequest("_index", "_type", "_id3").source(emptyMap()) + IndexRequest indexRequest3 = new IndexRequest("_index").id("_id3") + .source(emptyMap()) .setPipeline("does_not_exist") .setFinalPipeline("_none"); bulkRequest.add(indexRequest3); @@ -822,7 +822,8 @@ public void testExecuteSuccess() { ClusterState previousClusterState = clusterState; clusterState = IngestService.innerPut(putRequest, clusterState); ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); @SuppressWarnings("unchecked") @@ -852,7 +853,8 @@ public void testExecuteEmptyPipeline() throws Exception { ClusterState previousClusterState = clusterState; clusterState = IngestService.innerPut(putRequest, clusterState); ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); @SuppressWarnings("unchecked") @@ -910,7 +912,8 @@ public void testExecutePropagateAllMetadataUpdates() throws Exception { handler.accept(ingestDocument, null); return null; }).when(processor).execute(any(), any()); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); @SuppressWarnings("unchecked") @@ -929,7 +932,6 @@ public void testExecutePropagateAllMetadataUpdates() throws Exception { verify(failureHandler, never()).accept(any(), any()); verify(completionHandler, times(1)).accept(Thread.currentThread(), null); assertThat(indexRequest.index(), equalTo("update_index")); - assertThat(indexRequest.type(), equalTo("update_type")); assertThat(indexRequest.id(), equalTo("update_id")); assertThat(indexRequest.routing(), equalTo("update_routing")); assertThat(indexRequest.version(), equalTo(newVersion)); @@ -952,7 +954,8 @@ public void testExecuteFailure() throws Exception { ClusterState previousClusterState = clusterState; clusterState = IngestService.innerPut(putRequest, clusterState); ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); doThrow(new RuntimeException()).when(processor) @@ -1011,7 +1014,8 @@ public void testExecuteSuccessWithOnFailure() throws Exception { ClusterState previousClusterState = clusterState; clusterState = IngestService.innerPut(putRequest, clusterState); ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); @SuppressWarnings("unchecked") @@ -1053,7 +1057,8 @@ public void testExecuteFailureWithNestedOnFailure() throws Exception { ClusterState previousClusterState = clusterState; clusterState = IngestService.innerPut(putRequest, clusterState); ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); - final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()) + final IndexRequest indexRequest = new IndexRequest("_index").id("_id") + .source(emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); doThrow(new RuntimeException()).when(onFailureOnFailureProcessor) @@ -1089,12 +1094,12 @@ public void testBulkRequestExecutionWithFailures() throws Exception { DocWriteRequest request; if (randomBoolean()) { if (randomBoolean()) { - request = new DeleteRequest("_index", "_type", "_id"); + request = new DeleteRequest("_index", "_id"); } else { - request = new UpdateRequest("_index", "_type", "_id"); + request = new UpdateRequest("_index", "_id"); } } else { - IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId).setFinalPipeline("_none"); + IndexRequest indexRequest = new IndexRequest("_index").id("_id").setPipeline(pipelineId).setFinalPipeline("_none"); indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1"); request = indexRequest; numIndexRequests++; @@ -1154,7 +1159,7 @@ public void testBulkRequestExecution() throws Exception { logger.info("Using [{}], not randomly determined default [{}]", xContentType, Requests.INDEX_CONTENT_TYPE); int numRequest = scaledRandomIntBetween(8, 64); for (int i = 0; i < numRequest; i++) { - IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId).setFinalPipeline("_none"); + IndexRequest indexRequest = new IndexRequest("_index").id("_id").setPipeline(pipelineId).setFinalPipeline("_none"); indexRequest.source(xContentType, "field1", "value1"); bulkRequest.add(indexRequest); } @@ -1420,12 +1425,14 @@ public String getDescription() { ingestService.applyClusterState(new ClusterChangedEvent("", clusterState, previousClusterState)); BulkRequest bulkRequest = new BulkRequest(); - final IndexRequest indexRequest1 = new IndexRequest("_index", "_type", "_id1").source(Collections.emptyMap()) + final IndexRequest indexRequest1 = new IndexRequest("_index").id("_id1") + .source(Collections.emptyMap()) .setPipeline("_none") .setFinalPipeline("_none"); bulkRequest.add(indexRequest1); - IndexRequest indexRequest2 = new IndexRequest("_index", "_type", "_id2").source(Collections.emptyMap()) + IndexRequest indexRequest2 = new IndexRequest("_index").id("_id2") + .source(Collections.emptyMap()) .setPipeline("_id") .setFinalPipeline("_none"); bulkRequest.add(indexRequest2); @@ -1711,11 +1718,11 @@ private class IngestDocumentMatcher implements ArgumentMatcher { private final IngestDocument ingestDocument; IngestDocumentMatcher(String index, String type, String id, Map source) { - this.ingestDocument = new IngestDocument(index, type, id, null, null, null, source); + this.ingestDocument = new IngestDocument(index, id, null, null, null, source); } IngestDocumentMatcher(String index, String type, String id, Long version, VersionType versionType, Map source) { - this.ingestDocument = new IngestDocument(index, type, id, null, version, versionType, source); + this.ingestDocument = new IngestDocument(index, id, null, version, versionType, source); } @Override diff --git a/test/framework/src/main/java/org/opensearch/index/replication/OpenSearchIndexLevelReplicationTestCase.java b/test/framework/src/main/java/org/opensearch/index/replication/OpenSearchIndexLevelReplicationTestCase.java index c2bdcb231a4ea..5bb4ee5f29f16 100644 --- a/test/framework/src/main/java/org/opensearch/index/replication/OpenSearchIndexLevelReplicationTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/replication/OpenSearchIndexLevelReplicationTestCase.java @@ -246,7 +246,7 @@ protected EngineConfigFactory getEngineConfigFactory(IndexSettings indexSettings public int indexDocs(final int numOfDoc) throws Exception { for (int doc = 0; doc < numOfDoc; doc++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", Integer.toString(docId.incrementAndGet())) + final IndexRequest indexRequest = new IndexRequest(index.getName()).id(Integer.toString(docId.incrementAndGet())) .source("{}", XContentType.JSON); final BulkItemResponse response = index(indexRequest); if (response.isFailed()) { @@ -260,7 +260,7 @@ public int indexDocs(final int numOfDoc) throws Exception { public int appendDocs(final int numOfDoc) throws Exception { for (int doc = 0; doc < numOfDoc; doc++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type").source("{}", XContentType.JSON); + final IndexRequest indexRequest = new IndexRequest(index.getName()).source("{}", XContentType.JSON); final BulkItemResponse response = index(indexRequest); if (response.isFailed()) { throw response.getFailure().getCause(); diff --git a/test/framework/src/main/java/org/opensearch/ingest/RandomDocumentPicks.java b/test/framework/src/main/java/org/opensearch/ingest/RandomDocumentPicks.java index 70b290c38ceba..5d55f098a1f82 100644 --- a/test/framework/src/main/java/org/opensearch/ingest/RandomDocumentPicks.java +++ b/test/framework/src/main/java/org/opensearch/ingest/RandomDocumentPicks.java @@ -149,7 +149,6 @@ public static IngestDocument randomIngestDocument(Random random) { */ public static IngestDocument randomIngestDocument(Random random, Map source) { String index = randomString(random); - String type = randomString(random); String id = randomString(random); String routing = null; Long version = randomNonNegtiveLong(random); @@ -160,7 +159,7 @@ public static IngestDocument randomIngestDocument(Random random, Map randomSource(Random random) { diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java index f7789084985c3..dbc6dd012daee 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java @@ -1531,10 +1531,9 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, List builders) throws InterruptedException { Random random = random(); - Map> indicesAndTypes = new HashMap<>(); + Set indices = new HashSet<>(); for (IndexRequestBuilder builder : builders) { - final Set types = indicesAndTypes.computeIfAbsent(builder.request().index(), index -> new HashSet<>()); - types.add(builder.request().type()); + indices.add(builder.request().index()); } Set> bogusIds = new HashSet<>(); // (index, type, id) if (random.nextBoolean() && !builders.isEmpty() && dummyDocuments) { @@ -1543,22 +1542,18 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma final int numBogusDocs = scaledRandomIntBetween(1, builders.size() * 2); final int unicodeLen = between(1, 10); for (int i = 0; i < numBogusDocs; i++) { - String id = "bogus_doc_" - + randomRealisticUnicodeOfLength(unicodeLen) - + Integer.toString(dummmyDocIdGenerator.incrementAndGet()); - Map.Entry> indexAndTypes = RandomPicks.randomFrom(random, indicesAndTypes.entrySet()); - String index = indexAndTypes.getKey(); - String type = RandomPicks.randomFrom(random, indexAndTypes.getValue()); - bogusIds.add(Arrays.asList(index, type, id)); + String id = "bogus_doc_" + randomRealisticUnicodeOfLength(unicodeLen) + dummmyDocIdGenerator.incrementAndGet(); + String index = RandomPicks.randomFrom(random, indices); + bogusIds.add(Arrays.asList(index, id)); // We configure a routing key in case the mapping requires it - builders.add(client().prepareIndex(index, type, id).setSource("{}", XContentType.JSON).setRouting(id)); + builders.add(client().prepareIndex().setIndex(index).setId(id).setSource("{}", XContentType.JSON).setRouting(id)); } } Collections.shuffle(builders, random()); final CopyOnWriteArrayList> errors = new CopyOnWriteArrayList<>(); List inFlightAsyncOperations = new ArrayList<>(); // If you are indexing just a few documents then frequently do it one at a time. If many then frequently in bulk. - final String[] indices = indicesAndTypes.keySet().toArray(new String[0]); + final String[] indicesArray = indices.toArray(new String[] {}); if (builders.size() < FREQUENT_BULK_THRESHOLD ? frequently() : builders.size() < ALWAYS_BULK_THRESHOLD ? rarely() : false) { if (frequently()) { logger.info("Index [{}] docs async: [{}] bulk: [{}]", builders.size(), true, false); @@ -1566,13 +1561,13 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma indexRequestBuilder.execute( new PayloadLatchedActionListener<>(indexRequestBuilder, newLatch(inFlightAsyncOperations), errors) ); - postIndexAsyncActions(indices, inFlightAsyncOperations, maybeFlush); + postIndexAsyncActions(indicesArray, inFlightAsyncOperations, maybeFlush); } } else { logger.info("Index [{}] docs async: [{}] bulk: [{}]", builders.size(), false, false); for (IndexRequestBuilder indexRequestBuilder : builders) { indexRequestBuilder.execute().actionGet(); - postIndexAsyncActions(indices, inFlightAsyncOperations, maybeFlush); + postIndexAsyncActions(indicesArray, inFlightAsyncOperations, maybeFlush); } } } else { @@ -1608,15 +1603,15 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma // delete the bogus types again - it might trigger merges or at least holes in the segments and enforces deleted docs! for (List doc : bogusIds) { assertEquals( - "failed to delete a dummy doc [" + doc.get(0) + "][" + doc.get(2) + "]", + "failed to delete a dummy doc [" + doc.get(0) + "][" + doc.get(1) + "]", DocWriteResponse.Result.DELETED, - client().prepareDelete(doc.get(0), doc.get(1), doc.get(2)).setRouting(doc.get(2)).get().getResult() + client().prepareDelete(doc.get(0), null, doc.get(1)).setRouting(doc.get(1)).get().getResult() ); } } if (forceRefresh) { assertNoFailures( - client().admin().indices().prepareRefresh(indices).setIndicesOptions(IndicesOptions.lenientExpandOpen()).get() + client().admin().indices().prepareRefresh(indicesArray).setIndicesOptions(IndicesOptions.lenientExpandOpen()).get() ); } }