Deprecate types in index API (#36575)

* Deprecate types in index API

- deprecate type-based constructors of IndexRequest
- update tests to use typeless IndexRequest constructors
- no yaml tests as they have been already added in #35790

Relates to #35190
This commit is contained in:
Mayya Sharipova 2018-12-18 08:53:49 -05:00 committed by GitHub
parent 1a46d15bbd
commit f884b2b1cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 420 additions and 295 deletions

View File

@ -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);

View File

@ -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<SearchHit> 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"));

View File

@ -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

View File

@ -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);

View File

@ -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\"}");

View File

@ -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);
}

View File

@ -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();

View File

@ -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\": \"<p>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);
}

View File

@ -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());
}

View File

@ -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<IndexResponse> listener;
// tag::index-execute-listener
listener = new ActionListener<IndexResponse>() {
@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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"));

View File

@ -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"));

View File

@ -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"]
--------------------------------------------------

View File

@ -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`:

View File

@ -3,9 +3,9 @@
IMPORTANT: See <<removal-of-types>>.
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
<<indices-create-index,create index API>> 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 <<indices-put-mapping,put mapping>>
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 <<mapping,mapping>>
objects will automatically be added to the mapping definition.
Check out the <<mapping,mapping>>
section for more information on mapping definitions.
Automatic index creation can be disabled by setting

View File

@ -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<IndexRequestBuilder> 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);
}

View File

@ -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());
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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());

View File

@ -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;

View File

@ -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;

View File

@ -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());

View File

@ -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": {

View File

@ -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<IndexRequest> 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<IndexRequest> 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<IndexRequest> 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<IndexRequest> 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<IndexRequest> 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;

View File

@ -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());

View File

@ -73,7 +73,7 @@ public class IndexRequestTests extends ESTestCase {
Set<VersionType> 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();

View File

@ -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]}"));
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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" +

View File

@ -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<XContentBuilder, IOException> 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();

View File

@ -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<XContentBuilder, IOException> 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();

View File

@ -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) {

View File

@ -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);
}

View File

@ -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);