diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkProcessorIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkProcessorIT.java index 5989d9a9fe9..2b870dbc475 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkProcessorIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkProcessorIT.java @@ -240,12 +240,12 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase { for (int i = 1; i <= numDocs; i++) { if (randomBoolean()) { testDocs++; - processor.add(new IndexRequest("test", "_doc", Integer.toString(testDocs)) + processor.add(new IndexRequest("test").id(Integer.toString(testDocs)) .source(XContentType.JSON, "field", "value")); multiGetRequest.add("test", Integer.toString(testDocs)); } else { testReadOnlyDocs++; - processor.add(new IndexRequest("test-ro", "_doc", Integer.toString(testReadOnlyDocs)) + processor.add(new IndexRequest("test-ro").id(Integer.toString(testReadOnlyDocs)) .source(XContentType.JSON, "field", "value")); } } @@ -300,7 +300,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase { processor.add(new IndexRequest() // <1> .source(XContentType.JSON, "user", "some user")); - processor.add(new IndexRequest("blogs", "post_type", "1") // <2> + processor.add(new IndexRequest("blogs").id("1") // <2> .source(XContentType.JSON, "title", "some title")); } // end::bulk-processor-mix-parameters @@ -364,7 +364,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase { MultiGetRequest multiGetRequest = new MultiGetRequest(); for (int i = 1; i <= numDocs; i++) { if (randomBoolean()) { - processor.add(new IndexRequest(localIndex, "_doc", Integer.toString(i)) + processor.add(new IndexRequest(localIndex).id(Integer.toString(i)) .source(XContentType.JSON, "field", randomRealisticUnicodeOfLengthBetween(1, 30))); } else { BytesArray data = bytesBulkRequest(localIndex, "_doc", i); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkRequestWithGlobalParametersIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkRequestWithGlobalParametersIT.java index cf8f1ebfdbd..bb9f78622c8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkRequestWithGlobalParametersIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/BulkRequestWithGlobalParametersIT.java @@ -48,9 +48,9 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest createFieldAddingPipleine("xyz", "fieldNameXYZ", "valueXYZ"); BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("test", "doc", "1") + request.add(new IndexRequest("test").id("1") .source(XContentType.JSON, "field", "bulk1")); - request.add(new IndexRequest("test", "doc", "2") + request.add(new IndexRequest("test").id("2") .source(XContentType.JSON, "field", "bulk2")); request.pipeline("xyz"); @@ -67,10 +67,10 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest BulkRequest request = new BulkRequest(); request.pipeline("globalId"); - request.add(new IndexRequest("test", "doc", "1") + request.add(new IndexRequest("test").id("1") .source(XContentType.JSON, "field", "bulk1") .setPipeline("perIndexId")); - request.add(new IndexRequest("test", "doc", "2") + request.add(new IndexRequest("test").id("2") .source(XContentType.JSON, "field", "bulk2") .setPipeline("perIndexId")); @@ -91,11 +91,11 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest BulkRequest request = new BulkRequest(); request.pipeline("globalId"); - request.add(new IndexRequest("test", "doc", "1") + request.add(new IndexRequest("test").id("1") .source(XContentType.JSON, "field", "bulk1") .setPipeline("perIndexId")); // <1> - request.add(new IndexRequest("test", "doc", "2") + request.add(new IndexRequest("test").id("2") .source(XContentType.JSON, "field", "bulk2")); // <2> // end::bulk-request-mix-pipeline bulk(request); @@ -110,9 +110,9 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest public void testGlobalIndex() throws IOException { BulkRequest request = new BulkRequest("global_index", null); - request.add(new IndexRequest().type("doc").id("1") + request.add(new IndexRequest().id("1") .source(XContentType.JSON, "field", "bulk1")); - request.add(new IndexRequest().type("doc").id("2") + request.add(new IndexRequest().id("2") .source(XContentType.JSON, "field", "bulk2")); bulk(request); @@ -124,9 +124,9 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest @SuppressWarnings("unchecked") public void testIndexGlobalAndPerRequest() throws IOException { BulkRequest request = new BulkRequest("global_index", null); - request.add(new IndexRequest("local_index", "doc", "1") + request.add(new IndexRequest("local_index").id("1") .source(XContentType.JSON, "field", "bulk1")); - request.add(new IndexRequest().type("doc").id("2") // will take global index + request.add(new IndexRequest().id("2") // will take global index .source(XContentType.JSON, "field", "bulk2")); bulk(request); @@ -140,7 +140,7 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest } public void testGlobalType() throws IOException { - BulkRequest request = new BulkRequest(null, "global_type"); + BulkRequest request = new BulkRequest(null, "_doc"); request.add(new IndexRequest("index").id("1") .source(XContentType.JSON, "field", "bulk1")); request.add(new IndexRequest("index").id("2") @@ -149,10 +149,11 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest bulk(request); Iterable hits = searchAll("index"); - assertThat(hits, everyItem(hasType("global_type"))); + assertThat(hits, everyItem(hasType("_doc"))); } @SuppressWarnings("unchecked") + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/36549") public void testTypeGlobalAndPerRequest() throws IOException { BulkRequest request = new BulkRequest(null, "global_type"); request.add(new IndexRequest("index1", "local_type", "1") @@ -174,9 +175,9 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest public void testGlobalRouting() throws IOException { createIndexWithMultipleShards("index"); BulkRequest request = new BulkRequest(null, null); - request.add(new IndexRequest("index", "type", "1") + request.add(new IndexRequest("index").id("1") .source(XContentType.JSON, "field", "bulk1")); - request.add(new IndexRequest("index", "type", "2") + request.add(new IndexRequest("index").id("2") .source(XContentType.JSON, "field", "bulk1")); request.routing("1"); bulk(request); @@ -192,9 +193,9 @@ public class BulkRequestWithGlobalParametersIT extends ESRestHighLevelClientTest public void testMixLocalAndGlobalRouting() throws IOException { BulkRequest request = new BulkRequest(null, null); request.routing("globalRouting"); - request.add(new IndexRequest("index", "type", "1") + request.add(new IndexRequest("index").id("1") .source(XContentType.JSON, "field", "bulk1")); - request.add(new IndexRequest("index", "type", "2") + request.add(new IndexRequest("index").id( "2") .routing("localRouting") .source(XContentType.JSON, "field", "bulk1")); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java index 6fa65046672..59135204c5b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java @@ -69,6 +69,7 @@ import org.elasticsearch.rest.action.document.RestDeleteAction; import org.elasticsearch.rest.action.document.RestGetAction; import org.elasticsearch.rest.action.document.RestMultiGetAction; import org.elasticsearch.rest.action.document.RestUpdateAction; +import org.elasticsearch.rest.action.document.RestIndexAction; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; @@ -101,7 +102,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { // Testing deletion String docId = "id"; highLevelClient().index( - new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT); + new IndexRequest("index").id(docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT); DeleteRequest deleteRequest = new DeleteRequest("index", docId); if (randomBoolean()) { deleteRequest.version(1L); @@ -126,7 +127,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { // Testing version conflict String docId = "version_conflict"; highLevelClient().index( - new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT); + new IndexRequest("index").id( docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT); DeleteRequest deleteRequest = new DeleteRequest("index", docId).version(2); ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync)); @@ -139,7 +140,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { // Testing version type String docId = "version_type"; highLevelClient().index( - new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")) + new IndexRequest("index").id(docId).source(Collections.singletonMap("foo", "bar")) .versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT); DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(13); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); @@ -152,7 +153,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { // Testing version type with a wrong version String docId = "wrong_version"; highLevelClient().index( - new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")) + new IndexRequest("index").id(docId).source(Collections.singletonMap("foo", "bar")) .versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT); ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(10); @@ -166,7 +167,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { { // Testing routing String docId = "routing"; - highLevelClient().index(new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")).routing("foo"), + highLevelClient().index(new IndexRequest("index").id(docId).source(Collections.singletonMap("foo", "bar")).routing("foo"), RequestOptions.DEFAULT); DeleteRequest deleteRequest = new DeleteRequest("index", docId).routing("foo"); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); @@ -179,8 +180,13 @@ public class CrudIT extends ESRestHighLevelClientTestCase { public void testDeleteWithTypes() throws IOException { String docId = "id"; - highLevelClient().index(new IndexRequest("index", "type", docId) - .source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT); + IndexRequest indexRequest = new IndexRequest("index", "type", docId); + indexRequest.source(Collections.singletonMap("foo", "bar")); + execute(indexRequest, + highLevelClient()::index, + highLevelClient()::indexAsync, + expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE) + ); DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId); DeleteResponse deleteResponse = execute(deleteRequest, @@ -199,7 +205,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { GetRequest getRequest = new GetRequest("index", "id"); assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync)); } - IndexRequest index = new IndexRequest("index", "_doc", "id"); + IndexRequest index = new IndexRequest("index").id("id"); index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON); index.setRefreshPolicy(RefreshPolicy.IMMEDIATE); highLevelClient().index(index, RequestOptions.DEFAULT); @@ -222,7 +228,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { GetRequest getRequest = new GetRequest("index", "id"); assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync)); } - IndexRequest index = new IndexRequest("index", "_doc", "id"); + IndexRequest index = new IndexRequest("index").id("id"); index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON); index.setRefreshPolicy(RefreshPolicy.IMMEDIATE); highLevelClient().index(index, RequestOptions.DEFAULT); @@ -256,9 +262,9 @@ public class CrudIT extends ESRestHighLevelClientTestCase { RestStatus.OK, highLevelClient().bulk( new BulkRequest() - .add(new IndexRequest(noSourceIndex, "_doc", "1") + .add(new IndexRequest(noSourceIndex).id("1") .source(Collections.singletonMap("foo", 1), XContentType.JSON)) - .add(new IndexRequest(noSourceIndex, "_doc", "2") + .add(new IndexRequest(noSourceIndex).id("2") .source(Collections.singletonMap("foo", 2), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT @@ -281,7 +287,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]", exception.getMessage()); assertEquals("index", exception.getMetadata("es.index").get(0)); } - IndexRequest index = new IndexRequest("index", "_doc", "id"); + IndexRequest index = new IndexRequest("index").id("id"); String document = "{\"field1\":\"value1\",\"field2\":\"value2\"}"; index.source(document, XContentType.JSON); index.setRefreshPolicy(RefreshPolicy.IMMEDIATE); @@ -354,10 +360,14 @@ public class CrudIT extends ESRestHighLevelClientTestCase { public void testGetWithTypes() throws IOException { String document = "{\"field\":\"value\"}"; - IndexRequest index = new IndexRequest("index", "type", "id"); - index.source(document, XContentType.JSON); - index.setRefreshPolicy(RefreshPolicy.IMMEDIATE); - highLevelClient().index(index, RequestOptions.DEFAULT); + IndexRequest indexRequest = new IndexRequest("index", "type", "id"); + indexRequest.source(document, XContentType.JSON); + indexRequest.setRefreshPolicy(RefreshPolicy.IMMEDIATE); + execute(indexRequest, + highLevelClient()::index, + highLevelClient()::indexAsync, + expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE) + ); GetRequest getRequest = new GetRequest("index", "type", "id"); GetResponse getResponse = execute(getRequest, @@ -401,10 +411,10 @@ public class CrudIT extends ESRestHighLevelClientTestCase { } BulkRequest bulk = new BulkRequest(); bulk.setRefreshPolicy(RefreshPolicy.IMMEDIATE); - IndexRequest index = new IndexRequest("index", "_doc", "id1"); + IndexRequest index = new IndexRequest("index").id("id1"); index.source("{\"field\":\"value1\"}", XContentType.JSON); bulk.add(index); - index = new IndexRequest("index", "_doc", "id2"); + index = new IndexRequest("index").id("id2"); index.source("{\"field\":\"value2\"}", XContentType.JSON); bulk.add(index); highLevelClient().bulk(bulk, RequestOptions.DEFAULT); @@ -464,7 +474,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { public void testIndex() throws IOException { final XContentType xContentType = randomFrom(XContentType.values()); { - IndexRequest indexRequest = new IndexRequest("index", "_doc"); + IndexRequest indexRequest = new IndexRequest("index"); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("test", "test").endObject()); IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); @@ -485,7 +495,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertTrue(indexResponse.getShardInfo().getTotal() > 0); } { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("version", 1).endObject()); IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); @@ -495,7 +505,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertEquals("id", indexResponse.getId()); assertEquals(1L, indexResponse.getVersion()); - indexRequest = new IndexRequest("index", "_doc", "id"); + indexRequest = new IndexRequest("index").id("id"); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("version", 2).endObject()); indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync); @@ -506,7 +516,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertEquals(2L, indexResponse.getVersion()); ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { - IndexRequest wrongRequest = new IndexRequest("index", "_doc", "id"); + IndexRequest wrongRequest = new IndexRequest("index").id("id"); wrongRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject()); wrongRequest.version(5L); @@ -519,7 +529,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { } { ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "missing_pipeline"); + IndexRequest indexRequest = new IndexRequest("index").id("missing_pipeline"); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject()); indexRequest.setPipeline("missing"); @@ -531,7 +541,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { "reason=pipeline with id [missing] does not exist]", exception.getMessage()); } { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "external_version_type"); + IndexRequest indexRequest = new IndexRequest("index").id("external_version_type"); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject()); indexRequest.version(12L); indexRequest.versionType(VersionType.EXTERNAL); @@ -544,7 +554,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertEquals(12L, indexResponse.getVersion()); } { - final IndexRequest indexRequest = new IndexRequest("index", "_doc", "with_create_op_type"); + final IndexRequest indexRequest = new IndexRequest("index").id("with_create_op_type"); indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject()); indexRequest.opType(DocWriteRequest.OpType.CREATE); @@ -564,6 +574,22 @@ public class CrudIT extends ESRestHighLevelClientTestCase { } } + public void testIndexWithTypes() throws IOException { + final XContentType xContentType = randomFrom(XContentType.values()); + IndexRequest indexRequest = new IndexRequest("index", "some_type", "some_id"); + indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("test", "test").endObject()); + IndexResponse indexResponse = execute( + indexRequest, + highLevelClient()::index, + highLevelClient()::indexAsync, + expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE) + ); + assertEquals(RestStatus.CREATED, indexResponse.status()); + assertEquals("index", indexResponse.getIndex()); + assertEquals("some_type", indexResponse.getType()); + assertEquals("some_id",indexResponse.getId()); + } + public void testUpdate() throws IOException { { UpdateRequest updateRequest = new UpdateRequest("index", "does_not_exist"); @@ -576,7 +602,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { exception.getMessage()); } { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "id"); + IndexRequest indexRequest = new IndexRequest("index").id( "id"); indexRequest.source(singletonMap("field", "value")); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals(RestStatus.CREATED, indexResponse.status()); @@ -599,7 +625,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { "current version [2] is different than the one provided [1]]", exception.getMessage()); } { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "with_script"); + IndexRequest indexRequest = new IndexRequest("index").id("with_script"); indexRequest.source(singletonMap("counter", 12)); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals(RestStatus.CREATED, indexResponse.status()); @@ -617,7 +643,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { } { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "with_doc"); + IndexRequest indexRequest = new IndexRequest("index").id("with_doc"); indexRequest.source("field_1", "one", "field_3", "three"); indexRequest.version(12L); indexRequest.versionType(VersionType.EXTERNAL); @@ -641,7 +667,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { assertFalse(sourceAsMap.containsKey("field_3")); } { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "noop"); + IndexRequest indexRequest = new IndexRequest("index").id("noop"); indexRequest.source("field", "value"); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals(RestStatus.CREATED, indexResponse.status()); @@ -724,7 +750,11 @@ public class CrudIT extends ESRestHighLevelClientTestCase { public void testUpdateWithTypes() throws IOException { IndexRequest indexRequest = new IndexRequest("index", "type", "id"); indexRequest.source(singletonMap("field", "value")); - IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); + IndexResponse indexResponse = execute(indexRequest, + highLevelClient()::index, + highLevelClient()::indexAsync, + expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE) + ); UpdateRequest updateRequest = new UpdateRequest("index", "type", "id"); updateRequest.doc(singletonMap("field", "updated"), randomFrom(XContentType.values())); @@ -754,7 +784,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { if (erroneous == false) { assertEquals(RestStatus.CREATED, highLevelClient().index( - new IndexRequest("index", "_doc", id).source("field", -1), RequestOptions.DEFAULT).status()); + new IndexRequest("index").id(id).source("field", -1), RequestOptions.DEFAULT).status()); } DeleteRequest deleteRequest = new DeleteRequest("index", id); bulkRequest.add(deleteRequest); @@ -763,14 +793,14 @@ public class CrudIT extends ESRestHighLevelClientTestCase { BytesReference source = BytesReference.bytes(XContentBuilder.builder(xContentType.xContent()) .startObject().field("id", i).endObject()); if (opType == DocWriteRequest.OpType.INDEX) { - IndexRequest indexRequest = new IndexRequest("index", "_doc", id).source(source, xContentType); + IndexRequest indexRequest = new IndexRequest("index").id(id).source(source, xContentType); if (erroneous) { indexRequest.version(12L); } bulkRequest.add(indexRequest); } else if (opType == DocWriteRequest.OpType.CREATE) { - IndexRequest createRequest = new IndexRequest("index", "_doc", id).source(source, xContentType).create(true); + IndexRequest createRequest = new IndexRequest("index").id(id).source(source, xContentType).create(true); if (erroneous) { assertEquals(RestStatus.CREATED, highLevelClient().index(createRequest, RequestOptions.DEFAULT).status()); } @@ -782,7 +812,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { if (erroneous == false) { assertEquals(RestStatus.CREATED, highLevelClient().index( - new IndexRequest("index", "_doc", id).source("field", -1), RequestOptions.DEFAULT).status()); + new IndexRequest("index").id(id).source("field", -1), RequestOptions.DEFAULT).status()); } bulkRequest.add(updateRequest); } @@ -832,9 +862,9 @@ public class CrudIT extends ESRestHighLevelClientTestCase { RestStatus.OK, highLevelClient().bulk( new BulkRequest() - .add(new IndexRequest(sourceIndex, "_doc", "1") + .add(new IndexRequest(sourceIndex).id("1") .source(Collections.singletonMap("foo", 1), XContentType.JSON)) - .add(new IndexRequest(sourceIndex, "_doc", "2") + .add(new IndexRequest(sourceIndex).id("2") .source(Collections.singletonMap("foo", 2), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT @@ -942,11 +972,11 @@ public class CrudIT extends ESRestHighLevelClientTestCase { RestStatus.OK, highLevelClient().bulk( new BulkRequest() - .add(new IndexRequest(sourceIndex, "_doc", "1") + .add(new IndexRequest(sourceIndex).id("1") .source(Collections.singletonMap("foo", 1), XContentType.JSON)) - .add(new IndexRequest(sourceIndex, "_doc", "2") + .add(new IndexRequest(sourceIndex).id("2") .source(Collections.singletonMap("foo", 2), XContentType.JSON)) - .add(new IndexRequest(sourceIndex, "_doc", "3") + .add(new IndexRequest(sourceIndex).id("3") .source(Collections.singletonMap("foo", 3), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT @@ -1065,21 +1095,21 @@ public class CrudIT extends ESRestHighLevelClientTestCase { if (erroneous == false) { assertEquals(RestStatus.CREATED, highLevelClient().index( - new IndexRequest("index", "_doc", id).source("field", -1), RequestOptions.DEFAULT).status()); + new IndexRequest("index").id(id).source("field", -1), RequestOptions.DEFAULT).status()); } DeleteRequest deleteRequest = new DeleteRequest("index", id); processor.add(deleteRequest); } else { if (opType == DocWriteRequest.OpType.INDEX) { - IndexRequest indexRequest = new IndexRequest("index", "_doc", id).source(xContentType, "id", i); + IndexRequest indexRequest = new IndexRequest("index").id(id).source(xContentType, "id", i); if (erroneous) { indexRequest.version(12L); } processor.add(indexRequest); } else if (opType == DocWriteRequest.OpType.CREATE) { - IndexRequest createRequest = new IndexRequest("index", "_doc", id).source(xContentType, "id", i).create(true); + IndexRequest createRequest = new IndexRequest("index").id(id).source(xContentType, "id", i).create(true); if (erroneous) { assertEquals(RestStatus.CREATED, highLevelClient().index(createRequest, RequestOptions.DEFAULT).status()); } @@ -1091,7 +1121,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { if (erroneous == false) { assertEquals(RestStatus.CREATED, highLevelClient().index( - new IndexRequest("index", "_doc", id).source("field", -1), RequestOptions.DEFAULT).status()); + new IndexRequest("index").id(id).source("field", -1), RequestOptions.DEFAULT).status()); } processor.add(updateRequest); } @@ -1141,7 +1171,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { String expectedIndex = "logstash-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(DateTimeZone.UTC).monthOfYear().roundFloorCopy()); { - IndexRequest indexRequest = new IndexRequest(indexPattern, "_doc", "id#1"); + IndexRequest indexRequest = new IndexRequest(indexPattern).id("id#1"); indexRequest.source("field", "value"); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals(expectedIndex, indexResponse.getIndex()); @@ -1159,7 +1189,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { String docId = "this/is/the/id/中文"; { - IndexRequest indexRequest = new IndexRequest("index", "_doc", docId); + IndexRequest indexRequest = new IndexRequest("index").id(docId); indexRequest.source("field", "value"); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); assertEquals("index", indexResponse.getIndex()); @@ -1182,7 +1212,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase { //parameters are encoded by the low-level client but let's test that everything works the same when we use the high-level one String routing = "routing/中文value#1?"; { - IndexRequest indexRequest = new IndexRequest("index", "_doc", "id"); + IndexRequest indexRequest = new IndexRequest("index").id("id"); indexRequest.source("field", "value"); indexRequest.routing(routing); IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT); @@ -1216,9 +1246,9 @@ public class CrudIT extends ESRestHighLevelClientTestCase { RestStatus.OK, highLevelClient().bulk( new BulkRequest() - .add(new IndexRequest(sourceIndex, "_doc", "1") + .add(new IndexRequest(sourceIndex).id("1") .source(Collections.singletonMap("field", "value1"), XContentType.JSON)) - .add(new IndexRequest(sourceIndex, "_doc", "2") + .add(new IndexRequest(sourceIndex).id("2") .source(Collections.singletonMap("field", "value2"), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT @@ -1292,9 +1322,9 @@ public class CrudIT extends ESRestHighLevelClientTestCase { RestStatus.OK, highLevelClient().bulk( new BulkRequest() - .add(new IndexRequest(sourceIndex, "_doc", "1") + .add(new IndexRequest(sourceIndex).id("1") .source(Collections.singletonMap("field", "value1"), XContentType.JSON)) - .add(new IndexRequest(sourceIndex, "_doc", "2") + .add(new IndexRequest(sourceIndex).id("2") .source(Collections.singletonMap("field", "value2"), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/GraphIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/GraphIT.java index 3673afa1389..b5862178666 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/GraphIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/GraphIT.java @@ -41,23 +41,23 @@ public class GraphIT extends ESRestHighLevelClientTestCase { @Before public void indexDocuments() throws IOException { // Create chain of doc IDs across indices 1->2->3 - Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/type/1"); + Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/_doc/1"); doc1.setJsonEntity("{ \"num\":[1], \"const\":\"start\"}"); client().performRequest(doc1); - Request doc2 = new Request(HttpPut.METHOD_NAME, "/index2/type/1"); + Request doc2 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/1"); doc2.setJsonEntity("{\"num\":[1,2], \"const\":\"foo\"}"); client().performRequest(doc2); - Request doc3 = new Request(HttpPut.METHOD_NAME, "/index2/type/2"); + Request doc3 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/2"); doc3.setJsonEntity("{\"num\":[2,3], \"const\":\"foo\"}"); client().performRequest(doc3); - Request doc4 = new Request(HttpPut.METHOD_NAME, "/index_no_field_data/type/2"); + Request doc4 = new Request(HttpPut.METHOD_NAME, "/index_no_field_data/_doc/2"); doc4.setJsonEntity("{\"num\":\"string\", \"const\":\"foo\"}"); client().performRequest(doc4); - Request doc5 = new Request(HttpPut.METHOD_NAME, "/index_no_field_data/type/2"); + Request doc5 = new Request(HttpPut.METHOD_NAME, "/index_no_field_data/_doc/2"); doc5.setJsonEntity("{\"num\":[2,4], \"const\":\"foo\"}"); client().performRequest(doc5); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 5485e0f98a0..a639a09b3cc 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -909,8 +909,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { assertEquals("test_new", rolloverResponse.getNewIndex()); } - highLevelClient().index(new IndexRequest("test", "type", "1").source("field", "value"), RequestOptions.DEFAULT); - highLevelClient().index(new IndexRequest("test", "type", "2").source("field", "value") + highLevelClient().index(new IndexRequest("test").id("1").source("field", "value"), RequestOptions.DEFAULT); + highLevelClient().index(new IndexRequest("test").id("2").source("field", "value") .setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL), RequestOptions.DEFAULT); //without the refresh the rollover may not happen as the number of docs seen may be off @@ -1303,7 +1303,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { String index = "shakespeare"; createIndex(index, Settings.EMPTY); - Request postDoc = new Request(HttpPost.METHOD_NAME, "/" + index + "/1"); + Request postDoc = new Request(HttpPost.METHOD_NAME, "/" + index + "/_doc"); postDoc.setJsonEntity( "{\"type\":\"act\",\"line_id\":1,\"play_name\":\"Henry IV\", \"speech_number\":\"\"," + "\"line_number\":\"\",\"speaker\":\"\",\"text_entry\":\"ACT I\"}"); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java index 9a0a861cc13..31b0fe116cd 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java @@ -52,13 +52,13 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase { @Before public void indexDocuments() throws IOException { - Request berlin = new Request("PUT", "/index/doc/berlin"); + Request berlin = new Request("PUT", "/index/_doc/berlin"); berlin.setJsonEntity("{\"text\":\"berlin\"}"); client().performRequest(berlin); for (int i = 0; i < 6; i++) { // add another index to test basic multi index support String index = i == 0 ? "index2" : "index"; - Request amsterdam = new Request("PUT", "/" + index + "/doc/amsterdam" + i); + Request amsterdam = new Request("PUT", "/" + index + "/_doc/amsterdam" + i); amsterdam.setJsonEntity("{\"text\":\"amsterdam\"}"); client().performRequest(amsterdam); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index fa0f1c5708c..372b8caf1cb 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -608,8 +608,7 @@ public class RequestConvertersTests extends ESTestCase { public void testIndex() throws IOException { String index = randomAlphaOfLengthBetween(3, 10); - String type = randomAlphaOfLengthBetween(3, 10); - IndexRequest indexRequest = new IndexRequest(index, type); + IndexRequest indexRequest = new IndexRequest(index); String id = randomBoolean() ? randomAlphaOfLengthBetween(3, 10) : null; indexRequest.id(id); @@ -660,6 +659,50 @@ public class RequestConvertersTests extends ESTestCase { indexRequest.source(builder); } + Request request = RequestConverters.index(indexRequest); + if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) { + assertEquals("/" + index + "/_doc/" + id + "/_create", request.getEndpoint()); + } else if (id != null) { + assertEquals("/" + index + "/_doc/" + id, request.getEndpoint()); + } else { + assertEquals("/" + index + "/_doc", request.getEndpoint()); + } + assertEquals(expectedParams, request.getParameters()); + assertEquals(method, request.getMethod()); + + HttpEntity entity = request.getEntity(); + assertTrue(entity instanceof ByteArrayEntity); + assertEquals(indexRequest.getContentType().mediaTypeWithoutParameters(), entity.getContentType().getValue()); + try (XContentParser parser = createParser(xContentType.xContent(), entity.getContent())) { + assertEquals(nbFields, parser.map().size()); + } + } + + 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()); @@ -668,7 +711,6 @@ public class RequestConvertersTests extends ESTestCase { } else { assertEquals("/" + index + "/" + type, request.getEndpoint()); } - assertEquals(expectedParams, request.getParameters()); assertEquals(method, request.getMethod()); HttpEntity entity = request.getEntity(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java index b9f81903ed5..26b5b286e89 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java @@ -50,6 +50,7 @@ import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.join.aggregations.Children; import org.elasticsearch.join.aggregations.ChildrenAggregationBuilder; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.action.document.RestIndexAction; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.mustache.MultiSearchTemplateRequest; @@ -101,18 +102,23 @@ public class SearchIT extends ESRestHighLevelClientTestCase { public void indexDocuments() throws IOException { { Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/type/1"); + doc1.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); doc1.setJsonEntity("{\"type\":\"type1\", \"num\":10, \"num2\":50}"); client().performRequest(doc1); Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/type/2"); + doc2.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); doc2.setJsonEntity("{\"type\":\"type1\", \"num\":20, \"num2\":40}"); client().performRequest(doc2); Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/type/3"); + doc3.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); doc3.setJsonEntity("{\"type\":\"type1\", \"num\":50, \"num2\":35}"); client().performRequest(doc3); Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/type/4"); + doc4.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); doc4.setJsonEntity("{\"type\":\"type2\", \"num\":100, \"num2\":10}"); client().performRequest(doc4); Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/type/5"); + doc5.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); doc5.setJsonEntity("{\"type\":\"type2\", \"num\":100, \"num2\":10}"); client().performRequest(doc5); } @@ -400,7 +406,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { createIndex.setJsonEntity( "{\n" + " \"mappings\": {\n" + - " \"qa\" : {\n" + + " \"_doc\" : {\n" + " \"properties\" : {\n" + " \"qa_join_field\" : {\n" + " \"type\" : \"join\",\n" + @@ -411,7 +417,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { " }" + "}"); client().performRequest(createIndex); - Request questionDoc = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/qa/1"); + Request questionDoc = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/_doc/1"); questionDoc.setJsonEntity( "{\n" + " \"body\": \"

I have Windows 2003 server and i bought a new Windows 2008 server...\",\n" + @@ -424,7 +430,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { " \"qa_join_field\" : \"question\"\n" + "}"); client().performRequest(questionDoc); - Request answerDoc1 = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/qa/2"); + Request answerDoc1 = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/_doc/2"); answerDoc1.addParameter("routing", "1"); answerDoc1.setJsonEntity( "{\n" + @@ -441,7 +447,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { " \"creation_date\": \"2009-05-04T13:45:37.030\"\n" + "}"); client().performRequest(answerDoc1); - Request answerDoc2 = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/qa/3"); + Request answerDoc2 = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/_doc/3"); answerDoc2.addParameter("routing", "1"); answerDoc2.setJsonEntity( "{\n" + @@ -535,7 +541,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { } public void testSearchWithWeirdScriptFields() throws Exception { - Request doc = new Request("PUT", "test/type/1"); + Request doc = new Request("PUT", "test/_doc/1"); doc.setJsonEntity("{\"field\":\"value\"}"); client().performRequest(doc); client().performRequest(new Request("POST", "/test/_refresh")); @@ -579,7 +585,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase { public void testSearchScroll() throws Exception { for (int i = 0; i < 100; i++) { XContentBuilder builder = jsonBuilder().startObject().field("field", i).endObject(); - Request doc = new Request(HttpPut.METHOD_NAME, "/test/type1/" + Integer.toString(i)); + Request doc = new Request(HttpPut.METHOD_NAME, "/test/_doc/" + Integer.toString(i)); doc.setJsonEntity(Strings.toString(builder)); client().performRequest(doc); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksIT.java index 52e6d7d3bd7..28b909df5d4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/TasksIT.java @@ -82,8 +82,8 @@ public class TasksIT extends ESRestHighLevelClientTestCase { createIndex(sourceIndex, settings); createIndex(destinationIndex, settings); BulkRequest bulkRequest = new BulkRequest() - .add(new IndexRequest(sourceIndex, "type", "1").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)) - .add(new IndexRequest(sourceIndex, "type", "2").source(Collections.singletonMap("foo2", "bar2"), XContentType.JSON)) + .add(new IndexRequest(sourceIndex).id("1").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)) + .add(new IndexRequest(sourceIndex).id("2").source(Collections.singletonMap("foo2", "bar2"), XContentType.JSON)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE); assertEquals(RestStatus.OK, highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT).status()); @@ -111,7 +111,7 @@ public class TasksIT extends ESRestHighLevelClientTestCase { } TaskInfo info = taskResponse.getTaskInfo(); assertTrue(info.isCancellable()); - assertEquals("reindex from [source1] to [dest]", info.getDescription()); + assertEquals("reindex from [source1] to [dest][_doc]", info.getDescription()); assertEquals("indices:data/write/reindex", info.getAction()); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index 5279c19a415..6d0ceba00b5 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -116,8 +116,8 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { jsonMap.put("user", "kimchy"); jsonMap.put("postDate", new Date()); jsonMap.put("message", "trying out Elasticsearch"); - IndexRequest indexRequest = new IndexRequest("posts", "_doc", "1") - .source(jsonMap); // <1> + IndexRequest indexRequest = new IndexRequest("posts") + .id("1").source(jsonMap); // <1> //end::index-request-map IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult()); @@ -132,34 +132,33 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { builder.field("message", "trying out Elasticsearch"); } builder.endObject(); - IndexRequest indexRequest = new IndexRequest("posts", "_doc", "1") - .source(builder); // <1> + IndexRequest indexRequest = new IndexRequest("posts") + .id("1").source(builder); // <1> //end::index-request-xcontent IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); assertEquals(DocWriteResponse.Result.UPDATED, indexResponse.getResult()); } { //tag::index-request-shortcut - IndexRequest indexRequest = new IndexRequest("posts", "_doc", "1") - .source("user", "kimchy", - "postDate", new Date(), - "message", "trying out Elasticsearch"); // <1> + IndexRequest indexRequest = new IndexRequest("posts") + .id("1") + .source("user", "kimchy", + "postDate", new Date(), + "message", "trying out Elasticsearch"); // <1> //end::index-request-shortcut IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); assertEquals(DocWriteResponse.Result.UPDATED, indexResponse.getResult()); } { //tag::index-request-string - IndexRequest request = new IndexRequest( - "posts", // <1> - "_doc", // <2> - "1"); // <3> + IndexRequest request = new IndexRequest("posts"); // <1> + request.id("1"); // <2> String jsonString = "{" + "\"user\":\"kimchy\"," + "\"postDate\":\"2013-01-30\"," + "\"message\":\"trying out Elasticsearch\"" + "}"; - request.source(jsonString, XContentType.JSON); // <4> + request.source(jsonString, XContentType.JSON); // <3> //end::index-request-string // tag::index-execute @@ -169,7 +168,6 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { // tag::index-response String index = indexResponse.getIndex(); - String type = indexResponse.getType(); String id = indexResponse.getId(); long version = indexResponse.getVersion(); if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) { @@ -190,7 +188,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { // end::index-response } { - IndexRequest request = new IndexRequest("posts", "_doc", "1"); + IndexRequest request = new IndexRequest("posts").id("1"); // tag::index-request-routing request.routing("routing"); // <1> // end::index-request-routing @@ -218,9 +216,10 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { } { // tag::index-conflict - IndexRequest request = new IndexRequest("posts", "_doc", "1") - .source("field", "value") - .version(1); + IndexRequest request = new IndexRequest("posts") + .id("1") + .source("field", "value") + .version(1); try { IndexResponse response = client.index(request, RequestOptions.DEFAULT); } catch(ElasticsearchException e) { @@ -232,9 +231,10 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { } { // tag::index-optype - IndexRequest request = new IndexRequest("posts", "_doc", "1") - .source("field", "value") - .opType(DocWriteRequest.OpType.CREATE); + IndexRequest request = new IndexRequest("posts") + .id("1") + .source("field", "value") + .opType(DocWriteRequest.OpType.CREATE); try { IndexResponse response = client.index(request, RequestOptions.DEFAULT); } catch(ElasticsearchException e) { @@ -245,7 +245,9 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { // end::index-optype } { - IndexRequest request = new IndexRequest("posts", "_doc", "async").source("field", "value"); + IndexRequest request = new IndexRequest("posts") + .id("async") + .source("field", "value"); ActionListener listener; // tag::index-execute-listener listener = new ActionListener() { @@ -277,7 +279,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { public void testUpdate() throws Exception { RestHighLevelClient client = highLevelClient(); { - IndexRequest indexRequest = new IndexRequest("posts", "_doc", "1").source("field", 0); + IndexRequest indexRequest = new IndexRequest("posts").id("1").source("field", 0); IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); assertSame(RestStatus.CREATED, indexResponse.status()); @@ -552,7 +554,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { - IndexRequest indexRequest = new IndexRequest("posts", "_doc", "1").source("field", "value"); + IndexRequest indexRequest = new IndexRequest("posts").id("1").source("field", "value"); IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); assertSame(RestStatus.CREATED, indexResponse.status()); } @@ -620,7 +622,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { } { - IndexResponse indexResponse = client.index(new IndexRequest("posts", "_doc", "1").source("field", "value") + IndexResponse indexResponse = client.index(new IndexRequest("posts").id("1").source("field", "value") , RequestOptions.DEFAULT); assertSame(RestStatus.CREATED, indexResponse.status()); @@ -637,7 +639,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { // end::delete-conflict } { - IndexResponse indexResponse = client.index(new IndexRequest("posts", "_doc", "async").source("field", "value"), + IndexResponse indexResponse = client.index(new IndexRequest("posts").id("async").source("field", "value"), RequestOptions.DEFAULT); assertSame(RestStatus.CREATED, indexResponse.status()); @@ -676,11 +678,11 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { { // tag::bulk-request BulkRequest request = new BulkRequest(); // <1> - request.add(new IndexRequest("posts", "_doc", "1") // <2> + request.add(new IndexRequest("posts").id("1") // <2> .source(XContentType.JSON,"field", "foo")); - request.add(new IndexRequest("posts", "_doc", "2") // <3> + request.add(new IndexRequest("posts").id("2") // <3> .source(XContentType.JSON,"field", "bar")); - request.add(new IndexRequest("posts", "_doc", "3") // <4> + request.add(new IndexRequest("posts").id("3") // <4> .source(XContentType.JSON,"field", "baz")); // end::bulk-request // tag::bulk-execute @@ -695,7 +697,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { request.add(new DeleteRequest("posts", "3")); // <1> request.add(new UpdateRequest("posts", "2") // <2> .doc(XContentType.JSON,"other", "test")); - request.add(new IndexRequest("posts", "_doc", "4") // <3> + request.add(new IndexRequest("posts").id("4") // <3> .source(XContentType.JSON,"field", "baz")); // end::bulk-request-with-mixed-operations BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); @@ -1244,7 +1246,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { Response response = client().performRequest(createIndex); assertEquals(200, response.getStatusLine().getStatusCode()); - IndexRequest indexRequest = new IndexRequest("posts", "_doc", "1") + IndexRequest indexRequest = new IndexRequest("posts").id("1") .source("user", "kimchy", "postDate", new Date(), "message", "trying out Elasticsearch"); @@ -1472,13 +1474,13 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { assertNotNull(bulkProcessor); // tag::bulk-processor-add - IndexRequest one = new IndexRequest("posts", "_doc", "1"). - source(XContentType.JSON, "title", + IndexRequest one = new IndexRequest("posts").id("1") + .source(XContentType.JSON, "title", "In which order are my Elasticsearch queries executed?"); - IndexRequest two = new IndexRequest("posts", "_doc", "2") + IndexRequest two = new IndexRequest("posts").id("2") .source(XContentType.JSON, "title", "Current status and upcoming changes in Elasticsearch"); - IndexRequest three = new IndexRequest("posts", "_doc", "3") + IndexRequest three = new IndexRequest("posts").id("3") .source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch"); @@ -1546,7 +1548,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping("_doc", "user", "type=keyword"); CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT); assertTrue(authorsResponse.isAcknowledged()); - client.index(new IndexRequest("index", "_doc", "1").source("user", "kimchy"), RequestOptions.DEFAULT); + client.index(new IndexRequest("index").id("1").source("user", "kimchy"), RequestOptions.DEFAULT); Response refreshResponse = client().performRequest(new Request("POST", "/authors/_refresh")); assertEquals(200, refreshResponse.getStatusLine().getStatusCode()); @@ -1670,8 +1672,8 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping("_doc", "user", "type=text"); CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT); assertTrue(authorsResponse.isAcknowledged()); - client.index(new IndexRequest("index", "_doc", "1").source("user", "kimchy"), RequestOptions.DEFAULT); - client.index(new IndexRequest("index", "_doc", "2").source("user", "s1monw"), RequestOptions.DEFAULT); + client.index(new IndexRequest("index").id("1").source("user", "kimchy"), RequestOptions.DEFAULT); + client.index(new IndexRequest("index").id("2").source("user", "s1monw"), RequestOptions.DEFAULT); Response refreshResponse = client().performRequest(new Request("POST", "/authors/_refresh")); assertEquals(200, refreshResponse.getStatusLine().getStatusCode()); @@ -1764,7 +1766,8 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { source.put("foo", "val1"); source.put("bar", "val2"); source.put("baz", "val3"); - client.index(new IndexRequest("index", "_doc", "example_id") + client.index(new IndexRequest("index") + .id("example_id") .source(source) .setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java index bf507242bc8..29144dad28c 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/GraphDocumentationIT.java @@ -43,11 +43,11 @@ public class GraphDocumentationIT extends ESRestHighLevelClientTestCase { @Before public void indexDocuments() throws IOException { // Create chain of doc IDs across indices 1->2->3 - Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/type/1"); + Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/_doc/1"); doc1.setJsonEntity("{ \"participants\":[1,2], \"text\":\"let's start projectx\", \"attachment_md5\":\"324FHDGHFDG4564\"}"); client().performRequest(doc1); - Request doc2 = new Request(HttpPut.METHOD_NAME, "/index2/type/2"); + Request doc2 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/2"); doc2.setJsonEntity("{\"participants\":[2,3,4], \"text\":\"got something you both may be interested in\"}"); client().performRequest(doc2); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java index d049e02f52e..ff75cc32ae4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java @@ -82,7 +82,7 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { //tag::migration-request-ctor - IndexRequest request = new IndexRequest("index", "_doc", "id"); // <1> + IndexRequest request = new IndexRequest("index").id("id"); // <1> request.source("{\"field\":\"value\"}", XContentType.JSON); //end::migration-request-ctor diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java index 414e2553f84..5a4df9ecff4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java @@ -1497,13 +1497,13 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase { bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); { - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc"); + IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); indexRequest.source("{\"job_id\":\"test-get-overall-buckets-1\", \"result_type\":\"bucket\", \"timestamp\": 1533081600000," + "\"bucket_span\": 600,\"is_interim\": false, \"anomaly_score\": 60.0}", XContentType.JSON); bulkRequest.add(indexRequest); } { - IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc"); + IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared"); indexRequest.source("{\"job_id\":\"test-get-overall-buckets-2\", \"result_type\":\"bucket\", \"timestamp\": 1533081600000," + "\"bucket_span\": 3600,\"is_interim\": false, \"anomaly_score\": 100.0}", XContentType.JSON); bulkRequest.add(indexRequest); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java index 7996b9babab..dc85e85e9b2 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java @@ -305,11 +305,11 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts", "_doc", "1") + request.add(new IndexRequest("posts").id("1") .source(XContentType.JSON, "company", "Elastic", "age", 20)); - request.add(new IndexRequest("posts", "_doc", "2") + request.add(new IndexRequest("posts").id("2") .source(XContentType.JSON, "company", "Elastic", "age", 30)); - request.add(new IndexRequest("posts", "_doc", "3") + request.add(new IndexRequest("posts").id("3") .source(XContentType.JSON, "company", "Elastic", "age", 40)); request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); @@ -381,10 +381,10 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts", "_doc", "1").source(XContentType.JSON, "user", "kimchy")); - request.add(new IndexRequest("posts", "_doc", "2").source(XContentType.JSON, "user", "javanna")); - request.add(new IndexRequest("posts", "_doc", "3").source(XContentType.JSON, "user", "tlrx")); - request.add(new IndexRequest("posts", "_doc", "4").source(XContentType.JSON, "user", "cbuescher")); + request.add(new IndexRequest("posts").id("1").source(XContentType.JSON, "user", "kimchy")); + request.add(new IndexRequest("posts").id("2").source(XContentType.JSON, "user", "javanna")); + request.add(new IndexRequest("posts").id("3").source(XContentType.JSON, "user", "tlrx")); + request.add(new IndexRequest("posts").id("4").source(XContentType.JSON, "user", "cbuescher")); request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); assertSame(RestStatus.OK, bulkResponse.status()); @@ -424,13 +424,13 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts", "_doc", "1") + request.add(new IndexRequest("posts").id("1") .source(XContentType.JSON, "title", "In which order are my Elasticsearch queries executed?", "user", Arrays.asList("kimchy", "luca"), "innerObject", Collections.singletonMap("key", "value"))); - request.add(new IndexRequest("posts", "_doc", "2") + request.add(new IndexRequest("posts").id("2") .source(XContentType.JSON, "title", "Current status and upcoming changes in Elasticsearch", "user", Arrays.asList("kimchy", "christoph"), "innerObject", Collections.singletonMap("key", "value"))); - request.add(new IndexRequest("posts", "_doc", "3") + request.add(new IndexRequest("posts").id("3") .source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch", "user", Arrays.asList("kimchy", "tanguy"), "innerObject", Collections.singletonMap("key", "value"))); request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); @@ -487,7 +487,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { public void testSearchRequestProfiling() throws IOException { RestHighLevelClient client = highLevelClient(); { - IndexRequest request = new IndexRequest("posts", "_doc", "1") + IndexRequest request = new IndexRequest("posts").id("1") .source(XContentType.JSON, "tags", "elasticsearch", "comments", 123); request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT); @@ -559,11 +559,11 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { RestHighLevelClient client = highLevelClient(); { BulkRequest request = new BulkRequest(); - request.add(new IndexRequest("posts", "_doc", "1") + request.add(new IndexRequest("posts").id("1") .source(XContentType.JSON, "title", "In which order are my Elasticsearch queries executed?")); - request.add(new IndexRequest("posts", "_doc", "2") + request.add(new IndexRequest("posts").id("2") .source(XContentType.JSON, "title", "Current status and upcoming changes in Elasticsearch")); - request.add(new IndexRequest("posts", "_doc", "3") + request.add(new IndexRequest("posts").id("3") .source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch")); request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); @@ -1259,19 +1259,19 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { assertTrue(reviewersResponse.isAcknowledged()); BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add(new IndexRequest("posts", "_doc", "1") + bulkRequest.add(new IndexRequest("posts").id("1") .source(XContentType.JSON, "title", "In which order are my Elasticsearch queries executed?", "user", Arrays.asList("kimchy", "luca"), "innerObject", Collections.singletonMap("key", "value"))); - bulkRequest.add(new IndexRequest("posts", "_doc", "2") + bulkRequest.add(new IndexRequest("posts").id("2") .source(XContentType.JSON, "title", "Current status and upcoming changes in Elasticsearch", "user", Arrays.asList("kimchy", "christoph"), "innerObject", Collections.singletonMap("key", "value"))); - bulkRequest.add(new IndexRequest("posts", "_doc", "3") + bulkRequest.add(new IndexRequest("posts").id("3") .source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch", "user", Arrays.asList("kimchy", "tanguy"), "innerObject", Collections.singletonMap("key", "value"))); - bulkRequest.add(new IndexRequest("authors", "_doc", "1") + bulkRequest.add(new IndexRequest("authors").id("1") .source(XContentType.JSON, "user", "kimchy")); - bulkRequest.add(new IndexRequest("contributors", "_doc", "1") + bulkRequest.add(new IndexRequest("contributors").id("1") .source(XContentType.JSON, "user", "tanguy")); @@ -1373,17 +1373,17 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { assertTrue(authorsResponse.isAcknowledged()); BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add(new IndexRequest("blog", "_doc", "1") + bulkRequest.add(new IndexRequest("blog").id("1") .source(XContentType.JSON, "title", "Doubling Down on Open?", "user", Collections.singletonList("kimchy"), "innerObject", Collections.singletonMap("key", "value"))); - bulkRequest.add(new IndexRequest("blog", "_doc", "2") + bulkRequest.add(new IndexRequest("blog").id("2") .source(XContentType.JSON, "title", "Swiftype Joins Forces with Elastic", "user", Arrays.asList("kimchy", "matt"), "innerObject", Collections.singletonMap("key", "value"))); - bulkRequest.add(new IndexRequest("blog", "_doc", "3") + bulkRequest.add(new IndexRequest("blog").id("3") .source(XContentType.JSON, "title", "On Net Neutrality", "user", Arrays.asList("tyler", "kimchy"), "innerObject", Collections.singletonMap("key", "value"))); - bulkRequest.add(new IndexRequest("author", "_doc", "1") + bulkRequest.add(new IndexRequest("author").id("1") .source(XContentType.JSON, "user", "kimchy")); diff --git a/distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/NodeRestUsageIT.java b/distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/NodeRestUsageIT.java index 818037f68a1..2370548c6b6 100644 --- a/distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/NodeRestUsageIT.java +++ b/distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/NodeRestUsageIT.java @@ -80,12 +80,12 @@ public class NodeRestUsageIT extends ESRestTestCase { // Do some requests to get some rest usage stats client().performRequest(new Request("PUT", "/test")); for (int i = 0; i < 3; i++) { - final Request index = new Request("POST", "/test/doc/1"); + final Request index = new Request("POST", "/test/_doc/1"); index.setJsonEntity("{\"foo\": \"bar\"}"); client().performRequest(index); } client().performRequest(new Request("GET", "/test/_search")); - final Request index4 = new Request("POST", "/test/doc/4"); + final Request index4 = new Request("POST", "/test/_doc/4"); index4.setJsonEntity("{\"foo\": \"bar\"}"); client().performRequest(index4); client().performRequest(new Request("POST", "/test/_refresh")); diff --git a/docs/java-rest/high-level/document/index.asciidoc b/docs/java-rest/high-level/document/index.asciidoc index c5800e15056..9cdd8d3c557 100644 --- a/docs/java-rest/high-level/document/index.asciidoc +++ b/docs/java-rest/high-level/document/index.asciidoc @@ -17,9 +17,8 @@ An +{request}+ requires the following arguments: include-tagged::{doc-tests-file}[{api}-request-string] -------------------------------------------------- <1> Index -<2> Type -<3> Document id -<4> Document source provided as a `String` +<2> Document id for the request +<3> Document source provided as a `String` ==== Providing the document source The document source can be provided in different ways in addition to the @@ -124,7 +123,7 @@ include-tagged::{doc-tests-file}[{api}-conflict] <1> The raised exception indicates that a version conflict error was returned Same will happen in case `opType` was set to `create` and a document with -same index, type and id already existed: +same index and id already existed: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- diff --git a/docs/java-rest/high-level/migration.asciidoc b/docs/java-rest/high-level/migration.asciidoc index 662df0f5640..a42a9352faa 100644 --- a/docs/java-rest/high-level/migration.asciidoc +++ b/docs/java-rest/high-level/migration.asciidoc @@ -124,7 +124,7 @@ When request constructors are used, like in the following example: -------------------------------------------------- include-tagged::{doc-tests}/MigrationDocumentationIT.java[migration-request-ctor] -------------------------------------------------- -<1> Create an `IndexRequest` using its constructor +<1> Create an `IndexRequest` using its constructor and id() setter. The migration is very simple. The execution using the `TransportClient`: diff --git a/docs/reference/docs/index_.asciidoc b/docs/reference/docs/index_.asciidoc index 4aa6acbc816..15d78e961ab 100644 --- a/docs/reference/docs/index_.asciidoc +++ b/docs/reference/docs/index_.asciidoc @@ -3,9 +3,9 @@ IMPORTANT: See <>. -The index API adds or updates a typed JSON document in a specific index, +The index API adds or updates a JSON document in a specific index, making it searchable. The following example inserts the JSON document -into the "twitter" index, under a type called `_doc` with an id of 1: +into the "twitter" index with an id of 1: [source,js] -------------------------------------------------- @@ -60,13 +60,13 @@ The index operation automatically creates an index if it has not been created before (check out the <> for manually creating an index), and also automatically creates a -dynamic type mapping for the specific type if one has not yet been +dynamic mapping if one has not yet been created (check out the <> -API for manually creating a type mapping). +API for manually creating a mapping). The mapping itself is very flexible and is schema-free. New fields and -objects will automatically be added to the mapping definition of the -type specified. Check out the <> +objects will automatically be added to the mapping definition. +Check out the <> section for more information on mapping definitions. Automatic index creation can be disabled by setting diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java index 87c7c07007e..c077c992beb 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java @@ -46,7 +46,7 @@ public class ReindexFailureTests extends ReindexTestCase { * conflict on every request. */ indexRandom(true, - client().prepareIndex("dest", "test", "test").setSource("test", 10) /* Its a string in the source! */); + client().prepareIndex("dest", "_doc", "test").setSource("test", 10) /* Its a string in the source! */); indexDocs(100); @@ -70,7 +70,7 @@ public class ReindexFailureTests extends ReindexTestCase { public void testAbortOnVersionConflict() throws Exception { // Just put something in the way of the copy. indexRandom(true, - client().prepareIndex("dest", "test", "1").setSource("test", "test")); + client().prepareIndex("dest", "_doc", "1").setSource("test", "test")); indexDocs(100); @@ -81,7 +81,7 @@ public class ReindexFailureTests extends ReindexTestCase { BulkByScrollResponse response = copy.get(); assertThat(response, matcher().batches(1).versionConflicts(1).failures(1).created(99)); for (Failure failure: response.getBulkFailures()) { - assertThat(failure.getMessage(), containsString("VersionConflictEngineException[[test][")); + assertThat(failure.getMessage(), containsString("VersionConflictEngineException[[_doc][")); } } @@ -131,7 +131,7 @@ public class ReindexFailureTests extends ReindexTestCase { private void indexDocs(int count) throws Exception { List docs = new ArrayList<>(count); for (int i = 0; i < count; i++) { - docs.add(client().prepareIndex("source", "test", Integer.toString(i)).setSource("test", "words words")); + docs.add(client().prepareIndex("source", "_doc", Integer.toString(i)).setSource("test", "words words")); } indexRandom(true, docs); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexVersioningTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexVersioningTests.java index 472dec4675f..627238e5380 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexVersioningTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexVersioningTests.java @@ -113,18 +113,18 @@ public class ReindexVersioningTests extends ReindexTestCase { } private void setupSourceAbsent() throws Exception { - indexRandom(true, client().prepareIndex("source", "test", "test").setVersionType(EXTERNAL) + indexRandom(true, client().prepareIndex("source", "_doc", "test").setVersionType(EXTERNAL) .setVersion(SOURCE_VERSION).setSource("foo", "source")); - assertEquals(SOURCE_VERSION, client().prepareGet("source", "test", "test").get().getVersion()); + assertEquals(SOURCE_VERSION, client().prepareGet("source", "_doc", "test").get().getVersion()); } private void setupDest(int version) throws Exception { setupSourceAbsent(); - indexRandom(true, client().prepareIndex("dest", "test", "test").setVersionType(EXTERNAL) + indexRandom(true, client().prepareIndex("dest", "_doc", "test").setVersionType(EXTERNAL) .setVersion(version).setSource("foo", "dest")); - assertEquals(version, client().prepareGet("dest", "test", "test").get().getVersion()); + assertEquals(version, client().prepareGet("dest", "_doc", "test").get().getVersion()); } private void setupDestOlder() throws Exception { @@ -136,7 +136,7 @@ public class ReindexVersioningTests extends ReindexTestCase { } private void assertDest(String fooValue, int version) { - GetResponse get = client().prepareGet("dest", "test", "test").get(); + GetResponse get = client().prepareGet("dest", "_doc", "test").get(); assertEquals(fooValue, get.getSource().get("foo")); assertEquals(version, get.getVersion()); } diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/10_basic.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/10_basic.yml index 3557cf9bad7..9a8e46e9abf 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/10_basic.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/10_basic.yml @@ -3,7 +3,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: @@ -38,13 +38,13 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: index: index: dest - type: foo + type: _doc id: 1 body: { "text": "test" } - do: @@ -79,7 +79,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: @@ -136,13 +136,13 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: index: index: dest - type: foo + type: _doc id: 1 body: { "text": "test" } - do: @@ -162,12 +162,11 @@ - match: {version_conflicts: 1} - match: {batches: 1} - match: {failures.0.index: dest} - - match: {failures.0.type: foo} - match: {failures.0.id: "1"} - match: {failures.0.status: 409} - match: {failures.0.cause.type: version_conflict_engine_exception} # Use a regex so we don't mind if the version isn't always 1. Sometimes it comes out 2. - - match: {failures.0.cause.reason: "/\\[foo\\]\\[1\\]:.version.conflict,.document.already.exists.\\(current.version.\\[\\d+\\]\\)/"} + - match: {failures.0.cause.reason: "/\\[_doc\\]\\[1\\]:.version.conflict,.document.already.exists.\\(current.version.\\[\\d+\\]\\)/"} - match: {failures.0.cause.shard: /\d+/} - match: {failures.0.cause.index: dest} - gte: { took: 0 } @@ -184,13 +183,13 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: index: index: dest - type: foo + type: _doc id: 1 body: { "text": "test" } - do: @@ -225,7 +224,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: {} - do: @@ -243,7 +242,7 @@ - do: get: index: dest - type: foo + type: _doc id: 1 - match: { _source: {} } @@ -288,7 +287,7 @@ - do: get: index: dest - type: foo + type: _doc id: 1 - match: { _source.text: "test" } - is_false: _source.filtered diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/50_routing.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/50_routing.yml index 5c72aff84c0..362acebcc33 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/50_routing.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/50_routing.yml @@ -3,7 +3,7 @@ - do: index: index: src - type: test + type: _doc id: 1 body: { "company": "cat" } - do: @@ -22,7 +22,7 @@ - do: get: index: dest - type: test + type: _doc id: 1 routing: cat - match: { _routing: cat } @@ -32,7 +32,7 @@ - do: index: index: src - type: test + type: _doc id: 1 body: { "company": "cat" } routing: null @@ -52,6 +52,6 @@ - do: get: index: dest - type: test + type: _doc id: 1 - is_false: _routing diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/60_wait_for_active_shards.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/60_wait_for_active_shards.yml index 71601c35ac3..aee40112c7a 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/60_wait_for_active_shards.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/60_wait_for_active_shards.yml @@ -9,7 +9,7 @@ - do: index: index: src - type: test + type: _doc id: 1 body: {"text": "test"} - do: @@ -43,5 +43,5 @@ - do: get: index: dest - type: test + type: _doc id: 1 diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml index 1d380aa888e..3f8a83c43fe 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/85_scripting.yml @@ -3,7 +3,7 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: @@ -38,13 +38,13 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: index: index: twitter - type: tweet + type: _doc id: 2 body: { "user": "blort" } - do: @@ -89,13 +89,13 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: index: index: twitter - type: tweet + type: _doc id: 2 body: { "user": "foo" } - do: @@ -118,7 +118,7 @@ - do: get: index: new_twitter - type: tweet + type: _doc id: 1 routing: kimchy - match: { _routing: kimchy } @@ -126,7 +126,7 @@ - do: get: index: new_twitter - type: tweet + type: _doc id: 2 routing: foo - match: { _routing: foo } @@ -136,13 +136,13 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: index: index: twitter - type: tweet + type: _doc id: 2 body: { "user": "foo" } - do: @@ -192,13 +192,13 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: index: index: twitter - type: tweet + type: _doc id: 2 body: { "user": "foo" } - do: @@ -227,7 +227,7 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 version: 1 version_type: external @@ -235,7 +235,7 @@ - do: index: index: new_twitter - type: tweet + type: _doc id: 1 version: 1 version_type: external @@ -273,13 +273,13 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: index: index: new_twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: @@ -314,13 +314,13 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: index: index: twitter - type: tweet + type: _doc id: 2 body: { "user": "another" } - do: @@ -366,39 +366,39 @@ - do: index: index: index1 - type: type1 + type: _doc id: 1 body: { "lang": "en", "id": 123 } - do: index: index: index1 - type: type1 + type: _doc id: 2 body: { "lang": "en", "id": 456 } - do: index: index: index1 - type: type1 + type: _doc id: 3 body: { "lang": "fr", "id": 789 } # Destination index - do: index: index: index2 - type: type2 + type: _doc id: fr_789 body: { "lang": "fr", "id": 789 } - do: index: index: index2 - type: type2 + type: _doc id: en_123 body: { "lang": "en", "id": 123 } - do: indices.refresh: {} - # Reindex all documents from "index1" into "index2", changing their type - # to "type2" and their id to the concatened lang+id fields, + # Reindex all documents from "index1" into "index2", changing + # their id to the concatenated lang+id fields, # trashing all non-english pre existing ones - do: reindex: @@ -408,7 +408,6 @@ index: index1 dest: index: index2 - type: type2 script: lang: painless source: "ctx._id = ctx._source.lang + '_' + ctx._source.id; @@ -422,25 +421,22 @@ mget: body: docs: - - { _index: index2, _type: type2, _id: en_123} - - { _index: index2, _type: type2, _id: en_456} - - { _index: index2, _type: type2, _id: fr_789} + - { _index: index2, _type: _doc, _id: en_123} + - { _index: index2, _type: _doc, _id: en_456} + - { _index: index2, _type: _doc, _id: fr_789} - is_true: docs.0.found - match: { docs.0._index: index2 } - - match: { docs.0._type: type2 } - match: { docs.0._id: en_123 } - match: { docs.0._version: 2 } - is_true: docs.1.found - match: { docs.1._index: index2 } - - match: { docs.1._type: type2 } - match: { docs.1._id: en_456 } - match: { docs.1._version: 1 } - is_false: docs.2.found - match: { docs.2._index: index2 } - - match: { docs.2._type: type2 } - match: { docs.2._id: fr_789 } --- @@ -448,7 +444,7 @@ - do: index: index: twitter - type: tweet + type: _doc id: 1 body: { "user": "kimchy" } - do: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml index 8b8841fee78..4e0282b8fab 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yml @@ -3,7 +3,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } refresh: true @@ -59,13 +59,13 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: index: index: source - type: foo + type: _doc id: 2 body: { "text": "test2" } - do: @@ -116,7 +116,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } routing: foo @@ -169,7 +169,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } refresh: true @@ -227,14 +227,14 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } refresh: true - do: index: index: source - type: foo + type: _doc id: 2 body: { "text": "test" } refresh: true @@ -291,7 +291,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } refresh: true @@ -323,7 +323,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } refresh: true @@ -345,7 +345,7 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test", "filtered": "removed" } refresh: true @@ -385,7 +385,7 @@ - do: get: index: dest - type: foo + type: _doc id: 1 - match: { _source.text: "test" } - is_false: _source.filtered @@ -404,19 +404,19 @@ - do: index: index: source - type: foo + type: _doc id: 1 body: { "text": "test" } - do: index: index: source - type: foo + type: _doc id: 2 body: { "text": "test" } - do: index: index: source - type: foo + type: _doc id: 3 body: { "text": "test" } - do: diff --git a/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java b/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java index 8397646b12f..efac9ac2205 100644 --- a/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java +++ b/qa/ccs-unavailable-clusters/src/test/java/org/elasticsearch/search/CrossClusterSearchUnavailableClusterIT.java @@ -135,7 +135,7 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase { for (int i = 0; i < 10; i++) { restHighLevelClient.index( - new IndexRequest("index", "doc", String.valueOf(i)).source("field", "value"), RequestOptions.DEFAULT); + new IndexRequest("index").id(String.valueOf(i)).source("field", "value"), RequestOptions.DEFAULT); } Response refreshResponse = client().performRequest(new Request("POST", "/index/_refresh")); assertEquals(200, refreshResponse.getStatusLine().getStatusCode()); diff --git a/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java b/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java index 9da2dafc40b..62527908e16 100644 --- a/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java +++ b/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.seqno.SeqNoStats; import org.elasticsearch.rest.action.document.RestGetAction; +import org.elasticsearch.rest.action.document.RestIndexAction; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.yaml.ObjectPath; @@ -48,6 +49,7 @@ public class IndexingIT extends ESRestTestCase { final int id = idStart + i; Request request = new Request("PUT", index + "/doc/" + id); request.setJsonEntity("{\"test\": \"test_" + randomAlphaOfLength(2) + "\"}"); + request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); assertOK(client().performRequest(request)); } return numDocs; diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java index f7f847712ee..3666a64896a 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.rest.action.document.RestIndexAction; import org.elasticsearch.test.rest.yaml.ObjectPath; import java.io.IOException; @@ -89,6 +90,7 @@ public class RecoveryIT extends AbstractRollingTestCase { final int id = idStart + i; Request indexDoc = new Request("PUT", index + "/test/" + id); indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}"); + indexDoc.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); client().performRequest(indexDoc); } return numDocs; diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java index b287b49527a..c6233ad246b 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java @@ -52,7 +52,7 @@ public class HttpCompressionIT extends ESRestTestCase { assertEquals(200, response.getStatusLine().getStatusCode()); assertNull(response.getHeader(HttpHeaders.CONTENT_ENCODING)); - Request request = new Request("POST", "/company/employees/1"); + Request request = new Request("POST", "/company/_doc/1"); request.setJsonEntity(SAMPLE_DOCUMENT); response = client().performRequest(request); assertEquals(201, response.getStatusLine().getStatusCode()); 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 67df5658679..dcba05f6a38 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 @@ -3,7 +3,7 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html", "methods": ["POST", "PUT"], "url": { - "path": "/{index}/{type}", + "path": "/{index}/_doc", "paths": ["/{index}/{type}", "/{index}/{type}/{id}", "/{index}/_doc/{id}", "/{index}/_doc"], "parts": { "id": { diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 95473bf2ff2..e2c097a39b0 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -44,6 +44,7 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.seqno.SequenceNumbers; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.shard.ShardId; import java.io.IOException; @@ -80,7 +81,7 @@ public class IndexRequest extends ReplicatedWriteRequest implement */ static final int MAX_SOURCE_LENGTH_IN_TOSTRING = 2048; - private String type; + private String type = MapperService.SINGLE_MAPPING_NAME; private String id; @Nullable private String routing; @@ -123,7 +124,9 @@ public class IndexRequest extends ReplicatedWriteRequest implement /** * 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) { this.index = index; this.type = type; @@ -135,7 +138,10 @@ public class IndexRequest extends ReplicatedWriteRequest implement * @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) { this.index = index; this.type = type; @@ -227,7 +233,9 @@ public class IndexRequest extends ReplicatedWriteRequest implement /** * The type of the indexed document. + * @deprecated Types are in the process of being removed. */ + @Deprecated @Override public String type() { return type; @@ -235,7 +243,9 @@ public class IndexRequest extends ReplicatedWriteRequest implement /** * 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; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 2a64a43500e..bd18dae7454 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -19,9 +19,11 @@ package org.elasticsearch.rest.action.document; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.MapperService; @@ -38,6 +40,11 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestIndexAction extends BaseRestHandler { + private static final DeprecationLogger deprecationLogger = new DeprecationLogger( + LogManager.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} or /{index}/_doc endpoints instead."; + public RestIndexAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation @@ -79,13 +86,15 @@ public class RestIndexAction extends BaseRestHandler { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - final boolean includeTypeName = request.paramAsBoolean("include_type_name", true); + IndexRequest indexRequest; final String type = request.param("type"); - if (includeTypeName == false && MapperService.SINGLE_MAPPING_NAME.equals(type) == false) { - throw new IllegalArgumentException("You may only use the [include_type_name=false] option with the index APIs with the " + - "[{index}/_doc/{id}] and [{index}/_doc] endpoints."); + if (type.equals(MapperService.SINGLE_MAPPING_NAME) == false) { + deprecationLogger.deprecatedAndMaybeLog("index_with_types", TYPES_DEPRECATION_MESSAGE); + indexRequest = new IndexRequest(request.param("index"), type, request.param("id")); + } else { + indexRequest = new IndexRequest(request.param("index")); + indexRequest.id(request.param("id")); } - IndexRequest indexRequest = new IndexRequest(request.param("index"), type, request.param("id")); indexRequest.routing(request.param("routing")); indexRequest.setPipeline(request.param("pipeline")); indexRequest.source(request.requiredContent(), request.getXContentType()); diff --git a/server/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java b/server/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java index 3d87b8bd0be..3ab31b7d725 100644 --- a/server/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java @@ -73,7 +73,7 @@ public class IndexRequestTests extends ESTestCase { Set allButInternalSet = new HashSet<>(Arrays.asList(VersionType.values())); allButInternalSet.remove(VersionType.INTERNAL); VersionType[] allButInternal = allButInternalSet.toArray(new VersionType[]{}); - IndexRequest request = new IndexRequest("index", "type", "1"); + IndexRequest request = new IndexRequest("index").id("1"); request.opType(IndexRequest.OpType.CREATE); request.versionType(randomFrom(allButInternal)); assertThat(request.validate().validationErrors(), not(empty())); @@ -85,19 +85,19 @@ public class IndexRequestTests extends ESTestCase { public void testIndexingRejectsLongIds() { String id = randomAlphaOfLength(511); - IndexRequest request = new IndexRequest("index", "type", id); + IndexRequest request = new IndexRequest("index").id( id); request.source("{}", XContentType.JSON); ActionRequestValidationException validate = request.validate(); assertNull(validate); id = randomAlphaOfLength(512); - request = new IndexRequest("index", "type", id); + request = new IndexRequest("index").id( id); request.source("{}", XContentType.JSON); validate = request.validate(); assertNull(validate); id = randomAlphaOfLength(513); - request = new IndexRequest("index", "type", id); + request = new IndexRequest("index").id( id); request.source("{}", XContentType.JSON); validate = request.validate(); assertThat(validate, notNullValue()); @@ -106,7 +106,7 @@ public class IndexRequestTests extends ESTestCase { } public void testWaitForActiveShards() { - IndexRequest request = new IndexRequest("index", "type"); + IndexRequest request = new IndexRequest("index"); final int count = randomIntBetween(0, 10); request.waitForActiveShards(ActiveShardCount.from(count)); assertEquals(request.waitForActiveShards(), ActiveShardCount.from(count)); @@ -115,10 +115,10 @@ public class IndexRequestTests extends ESTestCase { } public void testAutoGenIdTimestampIsSet() { - IndexRequest request = new IndexRequest("index", "type"); + IndexRequest request = new IndexRequest("index"); request.process(Version.CURRENT, null, "index"); assertTrue("expected > 0 but got: " + request.getAutoGeneratedTimestamp(), request.getAutoGeneratedTimestamp() > 0); - request = new IndexRequest("index", "type", "1"); + request = new IndexRequest("index").id("1"); request.process(Version.CURRENT, null, "index"); assertEquals(IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, request.getAutoGeneratedTimestamp()); } @@ -156,7 +156,7 @@ public class IndexRequestTests extends ESTestCase { } public void testIndexRequestXContentSerialization() throws IOException { - IndexRequest indexRequest = new IndexRequest("foo", "bar", "1"); + IndexRequest indexRequest = new IndexRequest("foo").id("1"); indexRequest.source("{}", XContentType.JSON); assertEquals(XContentType.JSON, indexRequest.getContentType()); @@ -171,7 +171,7 @@ public class IndexRequestTests extends ESTestCase { // reindex makes use of index requests without a source so this needs to be handled public void testSerializationOfEmptyRequestWorks() throws IOException { - IndexRequest request = new IndexRequest("index", "type"); + IndexRequest request = new IndexRequest("index"); assertNull(request.getContentType()); try (BytesStreamOutput out = new BytesStreamOutput()) { request.writeTo(out); @@ -181,27 +181,26 @@ public class IndexRequestTests extends ESTestCase { serialized.readFrom(in); assertNull(request.getContentType()); assertEquals("index", request.index()); - assertEquals("type", request.type()); } } } public void testToStringSizeLimit() throws UnsupportedEncodingException { - IndexRequest request = new IndexRequest("index", "type"); + IndexRequest request = new IndexRequest("index"); String source = "{\"name\":\"value\"}"; request.source(source, XContentType.JSON); - assertEquals("index {[index][type][null], source[" + source + "]}", request.toString()); + assertEquals("index {[index][_doc][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][type][null], source[n/a, actual length: [" + new ByteSizeValue(actualBytes).toString() + + assertEquals("index {[index][_doc][null], source[n/a, actual length: [" + new ByteSizeValue(actualBytes).toString() + "], max length: " + new ByteSizeValue(IndexRequest.MAX_SOURCE_LENGTH_IN_TOSTRING).toString() + "]}", request.toString()); } public void testRejectsEmptyStringPipeline() { - IndexRequest request = new IndexRequest("index", "type"); + IndexRequest request = new IndexRequest("index"); request.source("{}", XContentType.JSON); request.setPipeline(""); ActionRequestValidationException validate = request.validate(); diff --git a/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java index 32bbadae134..e33c7ca5324 100644 --- a/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java @@ -659,6 +659,6 @@ public class UpdateRequestTests extends ESTestCase { request = new UpdateRequest("test", "type1", "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][null][null], source[{\"body\":\"bar\"}]}], scripted_upsert[false], detect_noop[true]}")); + + "doc[index {[null][_doc][null], source[{\"body\":\"bar\"}]}], scripted_upsert[false], detect_noop[true]}")); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java index d0c7210db2b..5fe99589a64 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java @@ -21,17 +21,40 @@ package org.elasticsearch.rest.action.document; import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.test.rest.RestActionTestCase; +import org.junit.Before; import static org.hamcrest.Matchers.equalTo; -import static org.mockito.Mockito.mock; -public class RestIndexActionTests extends ESTestCase { +public class RestIndexActionTests extends RestActionTestCase { + + private RestIndexAction action; + + @Before + public void setUpAction() { + action = new RestIndexAction(Settings.EMPTY, controller()); + } + + public void testTypeInPath() { + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/some_index/some_type/some_id") + .build(); + dispatchRequest(deprecatedRequest); + assertWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE); + + RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/some_index/_doc/some_id") + .build(); + dispatchRequest(validRequest); + } public void testCreateOpTypeValidation() throws Exception { Settings settings = settings(Version.CURRENT).build(); - RestIndexAction.CreateHandler create = new RestIndexAction(settings, mock(RestController.class)).new CreateHandler(settings); + RestIndexAction.CreateHandler create = action.new CreateHandler(settings); String opType = randomFrom("CREATE", null); create.validateOpType(opType); diff --git a/x-pack/plugin/ml/qa/basic-multi-node/src/test/java/org/elasticsearch/xpack/ml/integration/MlBasicMultiNodeIT.java b/x-pack/plugin/ml/qa/basic-multi-node/src/test/java/org/elasticsearch/xpack/ml/integration/MlBasicMultiNodeIT.java index 6e22e5b3f18..38cf3be2ec1 100644 --- a/x-pack/plugin/ml/qa/basic-multi-node/src/test/java/org/elasticsearch/xpack/ml/integration/MlBasicMultiNodeIT.java +++ b/x-pack/plugin/ml/qa/basic-multi-node/src/test/java/org/elasticsearch/xpack/ml/integration/MlBasicMultiNodeIT.java @@ -106,7 +106,7 @@ public class MlBasicMultiNodeIT extends ESRestTestCase { Request createAirlineDataRequest = new Request("PUT", "/airline-data"); createAirlineDataRequest.setJsonEntity("{" + " \"mappings\": {" - + " \"response\": {" + + " \"_doc\": {" + " \"properties\": {" + " \"time\": { \"type\":\"date\"}," + " \"airline\": { \"type\":\"keyword\"}," @@ -116,10 +116,10 @@ public class MlBasicMultiNodeIT extends ESRestTestCase { + " }" + "}"); client().performRequest(createAirlineDataRequest); - Request airlineData1 = new Request("PUT", "/airline-data/response/1"); + Request airlineData1 = new Request("PUT", "/airline-data/_doc/1"); airlineData1.setJsonEntity("{\"time\":\"2016-06-01T00:00:00Z\",\"airline\":\"AAA\",\"responsetime\":135.22}"); client().performRequest(airlineData1); - Request airlineData2 = new Request("PUT", "/airline-data/response/2"); + Request airlineData2 = new Request("PUT", "/airline-data/_doc/2"); airlineData2.setJsonEntity("{\"time\":\"2016-06-01T01:59:00Z\",\"airline\":\"AAA\",\"responsetime\":541.76}"); client().performRequest(airlineData2); @@ -265,7 +265,7 @@ public class MlBasicMultiNodeIT extends ESRestTestCase { xContentBuilder.startObject(); xContentBuilder.field("job_id", jobId); xContentBuilder.array("indexes", "airline-data"); - xContentBuilder.array("types", "response"); + xContentBuilder.array("types", "_doc"); xContentBuilder.field("_source", true); xContentBuilder.endObject(); Request request = new Request("PUT", MachineLearning.BASE_PATH + "datafeeds/" + datafeedId); diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java index 0283c2c29a3..4b0f9e7aac3 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java @@ -195,14 +195,14 @@ public class MlJobIT extends ESRestTestCase { { //create jobId1 docs String id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId1, "1234", 300); - Request createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/doc/" + id); + Request createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/_doc/" + id); createResultRequest.setJsonEntity(String.format(Locale.ROOT, "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"result_type\":\"bucket\", \"bucket_span\": \"%s\"}", jobId1, "1234", 1)); client().performRequest(createResultRequest); id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId1, "1236", 300); - createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/doc/" + id); + createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId1) + "/_doc/" + id); createResultRequest.setJsonEntity(String.format(Locale.ROOT, "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"result_type\":\"bucket\", \"bucket_span\": \"%s\"}", jobId1, "1236", 1)); @@ -220,14 +220,14 @@ public class MlJobIT extends ESRestTestCase { } { //create jobId2 docs String id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId2, "1234", 300); - Request createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId2) + "/doc/" + id); + Request createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId2) + "/_doc/" + id); createResultRequest.setJsonEntity(String.format(Locale.ROOT, "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"result_type\":\"bucket\", \"bucket_span\": \"%s\"}", jobId2, "1234", 1)); client().performRequest(createResultRequest); id = String.format(Locale.ROOT, "%s_bucket_%s_%s", jobId2, "1236", 300); - createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId2) + "/doc/" + id); + createResultRequest = new Request("PUT", AnomalyDetectorsIndex.jobResultsAliasedName(jobId2) + "/_doc/" + id); createResultRequest.setJsonEntity(String.format(Locale.ROOT, "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"result_type\":\"bucket\", \"bucket_span\": \"%s\"}", jobId2, "1236", 1)); @@ -510,20 +510,20 @@ public class MlJobIT extends ESRestTestCase { assertThat(indicesBeforeDelete, containsString(indexName + "-002")); // Add some documents to each index to make sure the DBQ clears them out - Request createDoc0 = new Request("PUT", indexName + "/doc/" + 123); + Request createDoc0 = new Request("PUT", indexName + "/_doc/" + 123); createDoc0.setJsonEntity(String.format(Locale.ROOT, "{\"job_id\":\"%s\", \"timestamp\": \"%s\", \"bucket_span\":%d, \"result_type\":\"record\"}", jobId, 123, 1)); client().performRequest(createDoc0); - Request createDoc1 = new Request("PUT", indexName + "-001/doc/" + 123); + Request createDoc1 = new Request("PUT", indexName + "-001/_doc/" + 123); createDoc1.setEntity(createDoc0.getEntity()); client().performRequest(createDoc1); - Request createDoc2 = new Request("PUT", indexName + "-002/doc/" + 123); + Request createDoc2 = new Request("PUT", indexName + "-002/_doc/" + 123); createDoc2.setEntity(createDoc0.getEntity()); client().performRequest(createDoc2); // Also index a few through the alias for the first job - Request createDoc3 = new Request("PUT", indexName + "/doc/" + 456); + Request createDoc3 = new Request("PUT", indexName + "/_doc/" + 456); createDoc3.setEntity(createDoc0.getEntity()); client().performRequest(createDoc3); diff --git a/x-pack/plugin/ml/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/ml/transforms/PainlessDomainSplitIT.java b/x-pack/plugin/ml/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/ml/transforms/PainlessDomainSplitIT.java index bc847e1a07d..c895ab2d4f5 100644 --- a/x-pack/plugin/ml/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/ml/transforms/PainlessDomainSplitIT.java +++ b/x-pack/plugin/ml/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/ml/transforms/PainlessDomainSplitIT.java @@ -182,7 +182,7 @@ public class PainlessDomainSplitIT extends ESRestTestCase { .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0); createIndex("painless", settings.build()); - Request createDoc = new Request("PUT", "/painless/test/1"); + Request createDoc = new Request("PUT", "/painless/_doc/1"); createDoc.setJsonEntity("{\"test\": \"test\"}"); createDoc.addParameter("refresh", "true"); client().performRequest(createDoc); @@ -262,7 +262,7 @@ public class PainlessDomainSplitIT extends ESRestTestCase { .put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1) .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0); - createIndex("painless", settings.build(), "\"test\": { \"properties\": { \"domain\": { \"type\": \"keyword\" }," + + createIndex("painless", settings.build(), "\"_doc\": { \"properties\": { \"domain\": { \"type\": \"keyword\" }," + "\"time\": { \"type\": \"date\" } } }"); // Index some data @@ -280,13 +280,13 @@ public class PainlessDomainSplitIT extends ESRestTestCase { if (i == 64) { // Anomaly has 100 docs, but we don't care about the value for (int j = 0; j < 100; j++) { - Request createDocRequest = new Request("PUT", "/painless/test/" + time.toDateTimeISO() + "_" + j); + Request createDocRequest = new Request("PUT", "/painless/_doc/" + time.toDateTimeISO() + "_" + j); createDocRequest.setJsonEntity("{\"domain\": \"" + "bar.bar.com\", \"time\": \"" + time.toDateTimeISO() + "\"}"); client().performRequest(createDocRequest); } } else { // Non-anomalous values will be what's seen when the anomaly is reported - Request createDocRequest = new Request("PUT", "/painless/test/" + time.toDateTimeISO()); + Request createDocRequest = new Request("PUT", "/painless/_doc/" + time.toDateTimeISO()); createDocRequest.setJsonEntity("{\"domain\": \"" + test.hostName + "\", \"time\": \"" + time.toDateTimeISO() + "\"}"); client().performRequest(createDocRequest); } @@ -300,7 +300,7 @@ public class PainlessDomainSplitIT extends ESRestTestCase { "{\n" + " \"job_id\":\"hrd-split-job\",\n" + " \"indexes\":[\"painless\"],\n" + - " \"types\":[\"test\"],\n" + + " \"types\":[\"_doc\"],\n" + " \"script_fields\": {\n" + " \"domain_split\": {\n" + " \"script\": \"return domainSplit(doc['domain'].value, params);\"\n" + diff --git a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java index 059a4ad2233..fe717d23a2c 100644 --- a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java +++ b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java @@ -10,6 +10,7 @@ import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.rest.action.document.RestIndexAction; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.sql.qa.cli.EmbeddedCli.SecurityConfig; import org.junit.After; @@ -59,6 +60,7 @@ public abstract class CliIntegrationTestCase extends ESRestTestCase { protected void index(String index, CheckedConsumer body) throws IOException { Request request = new Request("PUT", "/" + index + "/doc/1"); request.addParameter("refresh", "true"); + request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); XContentBuilder builder = JsonXContent.contentBuilder().startObject(); body.accept(builder); builder.endObject(); diff --git a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java index 1b147e2d2aa..02d5f7c06ca 100644 --- a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java +++ b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.rest.action.document.RestIndexAction; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.sql.jdbc.EsDataSource; import org.junit.After; @@ -85,6 +86,7 @@ public abstract class JdbcIntegrationTestCase extends ESRestTestCase { public static void index(String index, String documentId, CheckedConsumer body) throws IOException { Request request = new Request("PUT", "/" + index + "/doc/" + documentId); request.addParameter("refresh", "true"); + request.setOptions(expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)); XContentBuilder builder = JsonXContent.contentBuilder().startObject(); body.accept(builder); builder.endObject(); diff --git a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java index 3ca8878ad5e..f575c5ef408 100644 --- a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java +++ b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java @@ -720,7 +720,7 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe } private void index(String... docs) throws IOException { - Request request = new Request("POST", "/test/test/_bulk"); + Request request = new Request("POST", "/test/_doc/_bulk"); request.addParameter("refresh", "true"); StringBuilder bulk = new StringBuilder(); for (String doc : docs) { diff --git a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/GlobalCheckpointSyncActionIT.java b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/GlobalCheckpointSyncActionIT.java index 18cd67ff271..9d3e88cbc5c 100644 --- a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/GlobalCheckpointSyncActionIT.java +++ b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/GlobalCheckpointSyncActionIT.java @@ -73,7 +73,7 @@ public class GlobalCheckpointSyncActionIT extends ESRestTestCase { builder.field("foo", i); } builder.endObject(); - Request indexRequest = new Request("PUT", "/test-index/test-type/" + i); + Request indexRequest = new Request("PUT", "/test-index/_doc/" + i); indexRequest.setJsonEntity(Strings.toString(builder)); client().performRequest(indexRequest); } diff --git a/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java b/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java index f080c0bc43a..eb92bd29cd7 100644 --- a/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java +++ b/x-pack/qa/smoke-test-watcher-with-security/src/test/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java @@ -47,7 +47,7 @@ public class SmokeTestWatcherWithSecurityClientYamlTestSuiteIT extends ESClientY emptyList(), emptyMap()); // create one document in this index, so we can test in the YAML tests, that the index cannot be accessed - Request request = new Request("PUT", "/index_not_allowed_to_read/doc/1"); + Request request = new Request("PUT", "/index_not_allowed_to_read/_doc/1"); request.setJsonEntity("{\"foo\":\"bar\"}"); adminClient().performRequest(request);