Deprecate types in get, exists, and multi get. (#35930)

For each API, the following updates were made:
- Add deprecation warnings to `Rest*Action`, plus tests in `Rest*ActionTests`.
- For each REST yml test, make sure there is one version without types, and another legacy version that retains types (called *_with_types.yml).
- Deprecate relevant methods on the Java HLRC requests/ responses.
- Update documentation (for both the REST API and Java HLRC).
This commit is contained in:
Julie Tibshirani 2018-12-10 17:22:48 -08:00 committed by GitHub
parent b030125e23
commit 99f89cd3b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 1256 additions and 258 deletions

View File

@ -163,7 +163,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
for (BulkItemResponse bulkItemResponse : listener.bulkItems) {
assertThat(bulkItemResponse.getFailureMessage(), bulkItemResponse.isFailed(), equalTo(false));
assertThat(bulkItemResponse.getIndex(), equalTo("test"));
assertThat(bulkItemResponse.getType(), equalTo("test"));
assertThat(bulkItemResponse.getType(), equalTo("_doc"));
//with concurrent requests > 1 we can't rely on the order of the bulk requests
assertThat(Integer.valueOf(bulkItemResponse.getId()), both(greaterThan(0)).and(lessThanOrEqualTo(numDocs)));
//we do want to check that we don't get duplicate ids back
@ -240,12 +240,12 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
for (int i = 1; i <= numDocs; i++) {
if (randomBoolean()) {
testDocs++;
processor.add(new IndexRequest("test", "test", Integer.toString(testDocs))
processor.add(new IndexRequest("test", "_doc", Integer.toString(testDocs))
.source(XContentType.JSON, "field", "value"));
multiGetRequest.add("test", "test", Integer.toString(testDocs));
multiGetRequest.add("test", Integer.toString(testDocs));
} else {
testReadOnlyDocs++;
processor.add(new IndexRequest("test-ro", "test", Integer.toString(testReadOnlyDocs))
processor.add(new IndexRequest("test-ro", "_doc", Integer.toString(testReadOnlyDocs))
.source(XContentType.JSON, "field", "value"));
}
}
@ -262,7 +262,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
Set<String> readOnlyIds = new HashSet<>();
for (BulkItemResponse bulkItemResponse : listener.bulkItems) {
assertThat(bulkItemResponse.getIndex(), either(equalTo("test")).or(equalTo("test-ro")));
assertThat(bulkItemResponse.getType(), equalTo("test"));
assertThat(bulkItemResponse.getType(), equalTo("_doc"));
if (bulkItemResponse.getIndex().equals("test")) {
assertThat(bulkItemResponse.isFailed(), equalTo(false));
//with concurrent requests > 1 we can't rely on the order of the bulk requests
@ -330,12 +330,12 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
.setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs)
.setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB))
.setGlobalIndex("test")
.setGlobalType("test")
.setGlobalType("_doc")
.setGlobalRouting("routing")
.setGlobalPipeline("pipeline_id")
.build()) {
indexDocs(processor, numDocs, null, null, "test", "test", "pipeline_id");
indexDocs(processor, numDocs, null, null, "test", "pipeline_id");
latch.await();
assertThat(listener.beforeCounts.get(), equalTo(1));
@ -346,7 +346,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
Iterable<SearchHit> hits = searchAll(new SearchRequest("test").routing("routing"));
assertThat(hits, everyItem(hasProperty(fieldFromSource("fieldNameXYZ"), equalTo("valueXYZ"))));
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType("test"))));
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType("_doc"))));
assertThat(hits, containsInAnyOrder(expectedIds(numDocs)));
}
}
@ -359,18 +359,18 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
.<Matcher<SearchHit>>toArray(Matcher[]::new);
}
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, String localIndex, String localType,
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, String localIndex,
String globalIndex, String globalType, String globalPipeline) throws Exception {
MultiGetRequest multiGetRequest = new MultiGetRequest();
for (int i = 1; i <= numDocs; i++) {
if (randomBoolean()) {
processor.add(new IndexRequest(localIndex, localType, Integer.toString(i))
processor.add(new IndexRequest(localIndex, "_doc", Integer.toString(i))
.source(XContentType.JSON, "field", randomRealisticUnicodeOfLengthBetween(1, 30)));
} else {
BytesArray data = bytesBulkRequest(localIndex, localType, i);
BytesArray data = bytesBulkRequest(localIndex, "_doc", i);
processor.add(data, globalIndex, globalType, globalPipeline, null, XContentType.JSON);
}
multiGetRequest.add(localIndex, localType, Integer.toString(i));
multiGetRequest.add(localIndex, Integer.toString(i));
}
return multiGetRequest;
}
@ -396,7 +396,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
}
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) throws Exception {
return indexDocs(processor, numDocs, "test", "test", null, null, null);
return indexDocs(processor, numDocs, "test", null, null, null);
}
private static void assertResponseItems(List<BulkItemResponse> bulkItemResponses, int numDocs) {
@ -404,7 +404,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
int i = 1;
for (BulkItemResponse bulkItemResponse : bulkItemResponses) {
assertThat(bulkItemResponse.getIndex(), equalTo("test"));
assertThat(bulkItemResponse.getType(), equalTo("test"));
assertThat(bulkItemResponse.getType(), equalTo("_doc"));
assertThat(bulkItemResponse.getId(), equalTo(Integer.toString(i++)));
assertThat("item " + i + " failed with cause: " + bulkItemResponse.getFailureMessage(),
bulkItemResponse.isFailed(), equalTo(false));
@ -416,7 +416,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
int i = 1;
for (MultiGetItemResponse multiGetItemResponse : multiGetResponse) {
assertThat(multiGetItemResponse.getIndex(), equalTo("test"));
assertThat(multiGetItemResponse.getType(), equalTo("test"));
assertThat(multiGetItemResponse.getType(), equalTo("_doc"));
assertThat(multiGetItemResponse.getId(), equalTo(Integer.toString(i++)));
}
}

View File

@ -45,7 +45,6 @@ import static org.hamcrest.Matchers.lessThanOrEqualTo;
public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
private static final String INDEX_NAME = "index";
private static final String TYPE_NAME = "type";
private static BulkProcessor.Builder initBulkProcessorBuilder(BulkProcessor.Listener listener) {
return BulkProcessor.builder(
@ -144,9 +143,9 @@ public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) {
MultiGetRequest multiGetRequest = new MultiGetRequest();
for (int i = 1; i <= numDocs; i++) {
processor.add(new IndexRequest(INDEX_NAME, TYPE_NAME, Integer.toString(i))
processor.add(new IndexRequest(INDEX_NAME, "_doc", Integer.toString(i))
.source(XContentType.JSON, "field", randomRealisticUnicodeOfCodepointLengthBetween(1, 30)));
multiGetRequest.add(INDEX_NAME, TYPE_NAME, Integer.toString(i));
multiGetRequest.add(INDEX_NAME, Integer.toString(i));
}
return multiGetRequest;
}

View File

@ -175,7 +175,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
public void testExists() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
}
IndexRequest index = new IndexRequest("index", "_doc", "id");
@ -183,22 +183,22 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
highLevelClient().index(index, RequestOptions.DEFAULT);
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist");
GetRequest getRequest = new GetRequest("index", "does_not_exist");
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist").version(1);
GetRequest getRequest = new GetRequest("index", "does_not_exist").version(1);
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
}
}
public void testSourceExists() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
IndexRequest index = new IndexRequest("index", "_doc", "id");
@ -206,15 +206,15 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
highLevelClient().index(index, RequestOptions.DEFAULT);
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
assertTrue(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist");
GetRequest getRequest = new GetRequest("index", "does_not_exist");
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist").version(1);
GetRequest getRequest = new GetRequest("index", "does_not_exist").version(1);
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
}
@ -245,7 +245,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
);
}
{
GetRequest getRequest = new GetRequest(noSourceIndex, "_doc", "1");
GetRequest getRequest = new GetRequest(noSourceIndex, "1");
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
@ -253,7 +253,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
public void testGet() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
@ -266,7 +266,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
highLevelClient().index(index, RequestOptions.DEFAULT);
{
GetRequest getRequest = new GetRequest("index", "_doc", "id").version(2);
GetRequest getRequest = new GetRequest("index", "id").version(2);
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
assertEquals(RestStatus.CONFLICT, exception.status());
@ -275,7 +275,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals("index", exception.getMetadata("es.index").get(0));
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
if (randomBoolean()) {
getRequest.version(1L);
}
@ -289,7 +289,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals(document, getResponse.getSourceAsString());
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist");
GetRequest getRequest = new GetRequest("index", "does_not_exist");
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
assertEquals("index", getResponse.getIndex());
assertEquals("_doc", getResponse.getType());
@ -300,7 +300,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertNull(getResponse.getSourceAsString());
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
getRequest.fetchSourceContext(new FetchSourceContext(false, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY));
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
assertEquals("index", getResponse.getIndex());
@ -312,7 +312,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertNull(getResponse.getSourceAsString());
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "id");
GetRequest getRequest = new GetRequest("index", "id");
if (randomBoolean()) {
getRequest.fetchSourceContext(new FetchSourceContext(true, new String[]{"field1"}, Strings.EMPTY_ARRAY));
} else {
@ -334,15 +334,15 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
public void testMultiGet() throws IOException {
{
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.add("index", "_doc", "id1");
multiGetRequest.add("index", "_doc", "id2");
multiGetRequest.add("index", "id1");
multiGetRequest.add("index", "id2");
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::mget, highLevelClient()::mgetAsync);
assertEquals(2, response.getResponses().length);
assertTrue(response.getResponses()[0].isFailed());
assertNull(response.getResponses()[0].getResponse());
assertEquals("id1", response.getResponses()[0].getFailure().getId());
assertEquals("_doc", response.getResponses()[0].getFailure().getType());
assertNull(response.getResponses()[0].getFailure().getType());
assertEquals("index", response.getResponses()[0].getFailure().getIndex());
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]",
response.getResponses()[0].getFailure().getFailure().getMessage());
@ -350,7 +350,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertTrue(response.getResponses()[1].isFailed());
assertNull(response.getResponses()[1].getResponse());
assertEquals("id2", response.getResponses()[1].getId());
assertEquals("_doc", response.getResponses()[1].getType());
assertNull(response.getResponses()[1].getType());
assertEquals("index", response.getResponses()[1].getIndex());
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]",
response.getResponses()[1].getFailure().getFailure().getMessage());
@ -366,8 +366,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
highLevelClient().bulk(bulk, RequestOptions.DEFAULT);
{
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.add("index", "_doc", "id1");
multiGetRequest.add("index", "_doc", "id2");
multiGetRequest.add("index", "id1");
multiGetRequest.add("index", "id2");
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::mget, highLevelClient()::mgetAsync);
assertEquals(2, response.getResponses().length);
@ -789,7 +789,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals(0, bulkResponse.getSearchFailures().size());
assertEquals(
3,
(int) (highLevelClient().get(new GetRequest(sourceIndex, "_doc", "2"), RequestOptions.DEFAULT)
(int) (highLevelClient().get(new GetRequest(sourceIndex, "2"), RequestOptions.DEFAULT)
.getSourceAsMap().get("foo"))
);
}
@ -1059,7 +1059,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals("id#1", indexResponse.getId());
}
{
GetRequest getRequest = new GetRequest(indexPattern, "_doc", "id#1");
GetRequest getRequest = new GetRequest(indexPattern, "id#1");
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
assertTrue(getResponse.isExists());
assertEquals(expectedIndex, getResponse.getIndex());
@ -1077,7 +1077,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals(docId, indexResponse.getId());
}
{
GetRequest getRequest = new GetRequest("index", "_doc", docId);
GetRequest getRequest = new GetRequest("index", docId);
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
assertTrue(getResponse.isExists());
assertEquals("index", getResponse.getIndex());
@ -1101,7 +1101,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
assertEquals("id", indexResponse.getId());
}
{
GetRequest getRequest = new GetRequest("index", "_doc", "id").routing(routing);
GetRequest getRequest = new GetRequest("index", "id").routing(routing);
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
assertTrue(getResponse.isExists());
assertEquals("index", getResponse.getIndex());

View File

@ -527,7 +527,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
// Set up the index and docs
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
BulkRequest bulk = new BulkRequest();
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
@ -538,7 +538,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
while(pastCopy < now) {
IndexRequest doc = new IndexRequest();
doc.index(indexName);
doc.type("doc");
doc.type("_doc");
doc.id("id" + i);
doc.source("{\"total\":" +randomInt(1000) + ",\"timestamp\":"+ pastCopy +"}", XContentType.JSON);
bulk.add(doc);
@ -558,7 +558,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, jobId)
.setIndices(indexName)
.setQueryDelay(TimeValue.timeValueSeconds(1))
.setTypes(Arrays.asList("doc"))
.setTypes(Arrays.asList("_doc"))
.setFrequency(TimeValue.timeValueSeconds(1)).build();
machineLearningClient.putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT);
@ -603,7 +603,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
// Set up the index
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
// create the job and the datafeed
@ -667,7 +667,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
// Set up the index
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
// create the job and the datafeed
@ -736,7 +736,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
// Set up the index and docs
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
BulkRequest bulk = new BulkRequest();
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
@ -748,7 +748,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
Integer total = randomInt(1000);
IndexRequest doc = new IndexRequest();
doc.index(indexName);
doc.type("doc");
doc.type("_doc");
doc.id("id" + i);
doc.source("{\"total\":" + total + ",\"timestamp\":"+ thePast +"}", XContentType.JSON);
bulk.add(doc);
@ -768,7 +768,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, jobId)
.setIndices(indexName)
.setQueryDelay(TimeValue.timeValueSeconds(1))
.setTypes(Collections.singletonList("doc"))
.setTypes(Collections.singletonList("_doc"))
.setFrequency(TimeValue.timeValueSeconds(1)).build();
machineLearningClient.putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT);
@ -795,7 +795,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
String indexId = jobId + "-data";
// Set up the index and docs
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexId);
createIndexRequest.mapping("doc", "timestamp", "type=date,format=epoch_millis", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date,format=epoch_millis", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
BulkRequest bulk = new BulkRequest();
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
@ -809,7 +809,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
long timestamp = nowMillis - TimeValue.timeValueHours(totalBuckets - bucket).getMillis();
int bucketRate = bucket == anomalousBucket ? anomalousRate : normalRate;
for (int point = 0; point < bucketRate; point++) {
IndexRequest indexRequest = new IndexRequest(indexId, "doc");
IndexRequest indexRequest = new IndexRequest(indexId, "_doc");
indexRequest.source(XContentType.JSON, "timestamp", timestamp, "total", randomInt(1000));
bulk.add(indexRequest);
}
@ -819,7 +819,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
{
// Index a randomly named unused state document
String docId = "non_existing_job_" + randomFrom("model_state_1234567#1", "quantiles", "categorizer_state#1");
IndexRequest indexRequest = new IndexRequest(".ml-state", "doc", docId);
IndexRequest indexRequest = new IndexRequest(".ml-state", "_doc", docId);
indexRequest.source(Collections.emptyMap(), XContentType.JSON);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
@ -1388,7 +1388,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
String documentId = jobId + "_model_snapshot_" + snapshotId;
String snapshotUpdate = "{ \"timestamp\": " + timestamp + "}";
UpdateRequest updateSnapshotRequest = new UpdateRequest(".ml-anomalies-" + jobId, "doc", documentId);
UpdateRequest updateSnapshotRequest = new UpdateRequest(".ml-anomalies-" + jobId, "_doc", documentId);
updateSnapshotRequest.doc(snapshotUpdate.getBytes(StandardCharsets.UTF_8), XContentType.JSON);
highLevelClient().update(updateSnapshotRequest, RequestOptions.DEFAULT);
@ -1403,7 +1403,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, jobId)
.setIndices(indexName)
.setQueryDelay(TimeValue.timeValueSeconds(1))
.setTypes(Arrays.asList("doc"))
.setTypes(Arrays.asList("_doc"))
.setFrequency(TimeValue.timeValueSeconds(1)).build();
highLevelClient().machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT);
return datafeedId;
@ -1414,7 +1414,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
Job job = MachineLearningIT.buildJob(jobId);
highLevelClient().machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc", documentId);
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc", documentId);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"" + jobId + "\", \"timestamp\":1541587919000, " +
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", " +
@ -1434,7 +1434,7 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
for(String snapshotId : snapshotIds) {
String documentId = jobId + "_model_snapshot_" + snapshotId;
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc", documentId);
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc", documentId);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"" + jobId + "\", \"timestamp\":1541587919000, " +
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", " +

View File

@ -1258,8 +1258,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
//tag::get-request
GetRequest getRequest = new GetRequest(
"posts", // <1>
"_doc", // <2>
"1"); // <3>
"1"); // <2>
//end::get-request
//tag::get-execute
@ -1282,7 +1281,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
//end::get-response
}
{
GetRequest request = new GetRequest("posts", "_doc", "1");
GetRequest request = new GetRequest("posts", "1");
//tag::get-request-no-source
request.fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE); // <1>
//end::get-request-no-source
@ -1290,7 +1289,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
assertNull(getResponse.getSourceInternal());
}
{
GetRequest request = new GetRequest("posts", "_doc", "1");
GetRequest request = new GetRequest("posts", "1");
//tag::get-request-source-include
String[] includes = new String[]{"message", "*Date"};
String[] excludes = Strings.EMPTY_ARRAY;
@ -1305,7 +1304,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(sourceAsMap.containsKey("postDate"));
}
{
GetRequest request = new GetRequest("posts", "_doc", "1");
GetRequest request = new GetRequest("posts", "1");
//tag::get-request-source-exclude
String[] includes = Strings.EMPTY_ARRAY;
String[] excludes = new String[]{"message"};
@ -1320,7 +1319,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(sourceAsMap.containsKey("postDate"));
}
{
GetRequest request = new GetRequest("posts", "_doc", "1");
GetRequest request = new GetRequest("posts", "1");
//tag::get-request-stored
request.storedFields("message"); // <1>
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
@ -1331,7 +1330,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
assertNull(getResponse.getSourceInternal());
}
{
GetRequest request = new GetRequest("posts", "_doc", "1");
GetRequest request = new GetRequest("posts", "1");
//tag::get-request-routing
request.routing("routing"); // <1>
//end::get-request-routing
@ -1352,7 +1351,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
//end::get-request-version-type
}
{
GetRequest request = new GetRequest("posts", "_doc", "1");
GetRequest request = new GetRequest("posts", "1");
// tag::get-execute-listener
ActionListener<GetResponse> listener = new ActionListener<GetResponse>() {
@ -1380,7 +1379,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
}
{
//tag::get-indexnotfound
GetRequest request = new GetRequest("does_not_exist", "_doc", "1");
GetRequest request = new GetRequest("does_not_exist", "1");
try {
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
} catch (ElasticsearchException e) {
@ -1393,7 +1392,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
{
// tag::get-conflict
try {
GetRequest request = new GetRequest("posts", "_doc", "1").version(2);
GetRequest request = new GetRequest("posts", "1").version(2);
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
} catch (ElasticsearchException exception) {
if (exception.status() == RestStatus.CONFLICT) {
@ -1409,10 +1408,9 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
// tag::exists-request
GetRequest getRequest = new GetRequest(
"posts", // <1>
"_doc", // <2>
"1"); // <3>
getRequest.fetchSourceContext(new FetchSourceContext(false)); // <4>
getRequest.storedFields("_none_"); // <5>
"1"); // <2>
getRequest.fetchSourceContext(new FetchSourceContext(false)); // <3>
getRequest.storedFields("_none_"); // <4>
// end::exists-request
{
// tag::exists-execute
@ -1779,18 +1777,17 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
MultiGetRequest request = new MultiGetRequest();
request.add(new MultiGetRequest.Item(
"index", // <1>
"_doc", // <2>
"example_id")); // <3>
request.add(new MultiGetRequest.Item("index", "_doc", "another_id")); // <4>
"example_id")); // <2>
request.add(new MultiGetRequest.Item("index", "another_id")); // <3>
// end::multi-get-request
// Add a missing index so we can test it.
request.add(new MultiGetRequest.Item("missing_index", "_doc", "id"));
request.add(new MultiGetRequest.Item("missing_index", "id"));
// tag::multi-get-request-item-extras
request.add(new MultiGetRequest.Item("index", "_doc", "with_routing")
request.add(new MultiGetRequest.Item("index", "with_routing")
.routing("some_routing")); // <1>
request.add(new MultiGetRequest.Item("index", "_doc", "with_version")
request.add(new MultiGetRequest.Item("index", "with_version")
.versionType(VersionType.EXTERNAL) // <2>
.version(10123L)); // <3>
// end::multi-get-request-item-extras
@ -1809,7 +1806,6 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
assertNull(firstItem.getFailure()); // <1>
GetResponse firstGet = firstItem.getResponse(); // <2>
String index = firstItem.getIndex();
String type = firstItem.getType();
String id = firstItem.getId();
if (firstGet.isExists()) {
long version = firstGet.getVersion();
@ -1863,7 +1859,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
{
MultiGetRequest request = new MultiGetRequest();
// tag::multi-get-request-no-source
request.add(new MultiGetRequest.Item("index", "_doc", "example_id")
request.add(new MultiGetRequest.Item("index", "example_id")
.fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE)); // <1>
// end::multi-get-request-no-source
MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT));
@ -1876,7 +1872,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
String[] excludes = Strings.EMPTY_ARRAY;
FetchSourceContext fetchSourceContext =
new FetchSourceContext(true, includes, excludes);
request.add(new MultiGetRequest.Item("index", "_doc", "example_id")
request.add(new MultiGetRequest.Item("index", "example_id")
.fetchSourceContext(fetchSourceContext)); // <1>
// end::multi-get-request-source-include
MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT));
@ -1891,7 +1887,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
String[] excludes = new String[] {"foo", "*r"};
FetchSourceContext fetchSourceContext =
new FetchSourceContext(true, includes, excludes);
request.add(new MultiGetRequest.Item("index", "_doc", "example_id")
request.add(new MultiGetRequest.Item("index", "example_id")
.fetchSourceContext(fetchSourceContext)); // <1>
// end::multi-get-request-source-exclude
MultiGetItemResponse item = unwrapAndAssertExample(client.mget(request, RequestOptions.DEFAULT));
@ -1902,7 +1898,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
{
MultiGetRequest request = new MultiGetRequest();
// tag::multi-get-request-stored
request.add(new MultiGetRequest.Item("index", "_doc", "example_id")
request.add(new MultiGetRequest.Item("index", "example_id")
.storedFields("foo")); // <1>
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
MultiGetItemResponse item = response.getResponses()[0];
@ -1914,7 +1910,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
{
// tag::multi-get-conflict
MultiGetRequest request = new MultiGetRequest();
request.add(new MultiGetRequest.Item("index", "_doc", "example_id")
request.add(new MultiGetRequest.Item("index", "example_id")
.version(1000L));
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
MultiGetItemResponse item = response.getResponses()[0];

View File

@ -106,7 +106,7 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
}
});
//end::migration-request-async-execution
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "_doc", "id"), RequestOptions.DEFAULT)));
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "id"), RequestOptions.DEFAULT)));
}
{
//tag::migration-request-sync-execution

View File

@ -764,7 +764,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
// tag::get-datafeed-execute
GetDatafeedResponse response = client.machineLearning().getDatafeed(request, RequestOptions.DEFAULT);
// end::get-datafeed-execute
// tag::get-datafeed-response
long numberOfDatafeeds = response.count(); // <1>
List<DatafeedConfig> datafeeds = response.datafeeds(); // <2>
@ -823,7 +823,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
AcknowledgedResponse deleteDatafeedResponse = client.machineLearning().deleteDatafeed(
deleteDatafeedRequest, RequestOptions.DEFAULT);
// end::delete-datafeed-execute
// tag::delete-datafeed-response
boolean isAcknowledged = deleteDatafeedResponse.isAcknowledged(); // <1>
// end::delete-datafeed-response
@ -869,10 +869,10 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
String datafeedId = job.getId() + "-feed";
String indexName = "preview_data_2";
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId())
.setTypes(Arrays.asList("doc"))
.setTypes(Arrays.asList("_doc"))
.setIndices(indexName)
.build();
client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT);
@ -929,10 +929,10 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
String datafeedId = job.getId() + "-feed";
String indexName = "start_data_2";
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId())
.setTypes(Arrays.asList("doc"))
.setTypes(Arrays.asList("_doc"))
.setIndices(indexName)
.build();
client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT);
@ -1050,17 +1050,17 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
String datafeedId1 = job.getId() + "-feed";
String indexName = "datafeed_stats_data_2";
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.mapping("doc", "timestamp", "type=date", "total", "type=long");
createIndexRequest.mapping("_doc", "timestamp", "type=date", "total", "type=long");
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId1, job.getId())
.setTypes(Arrays.asList("doc"))
.setTypes(Arrays.asList("_doc"))
.setIndices(indexName)
.build();
client.machineLearning().putDatafeed(new PutDatafeedRequest(datafeed), RequestOptions.DEFAULT);
String datafeedId2 = secondJob.getId() + "-feed";
DatafeedConfig secondDatafeed = DatafeedConfig.builder(datafeedId2, secondJob.getId())
.setTypes(Arrays.asList("doc"))
.setTypes(Arrays.asList("_doc"))
.setIndices(indexName)
.build();
client.machineLearning().putDatafeed(new PutDatafeedRequest(secondDatafeed), RequestOptions.DEFAULT);
@ -1123,7 +1123,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a bucket
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc");
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"test-get-buckets\", \"result_type\":\"bucket\", \"timestamp\": 1533081600000," +
"\"bucket_span\": 600,\"is_interim\": false, \"anomaly_score\": 80.0}", XContentType.JSON);
@ -1277,7 +1277,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
}
public void testDeleteForecast() throws Exception {
RestHighLevelClient client = highLevelClient();
@ -1356,7 +1356,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
}
public void testGetJobStats() throws Exception {
RestHighLevelClient client = highLevelClient();
@ -1481,7 +1481,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
}
public void testGetOverallBuckets() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();
@ -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", "_doc");
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", "_doc");
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);
@ -1591,7 +1591,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a record
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc");
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"test-get-records\", \"result_type\":\"record\", \"timestamp\": 1533081600000," +
"\"bucket_span\": 600,\"is_interim\": false, \"record_score\": 80.0}", XContentType.JSON);
@ -1810,7 +1810,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a record
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc");
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"test-get-influencers\", \"result_type\":\"influencer\", \"timestamp\": 1533081600000," +
"\"bucket_span\": 600,\"is_interim\": false, \"influencer_score\": 80.0, \"influencer_field_name\": \"my_influencer\"," +
@ -1901,7 +1901,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a category
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc");
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\": \"test-get-categories\", \"category_id\": 1, \"terms\": \"AAL\"," +
" \"regex\": \".*?AAL.*\", \"max_matching_length\": 3, \"examples\": [\"AAL\"]}", XContentType.JSON);
@ -2022,7 +2022,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a snapshot
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc");
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"" + jobId + "\", \"timestamp\":1541587919000, " +
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", " +
@ -2088,7 +2088,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a snapshot
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc");
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"test-get-model-snapshots\", \"timestamp\":1541587919000, " +
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", " +
@ -2186,7 +2186,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
// Let us index a snapshot
String documentId = jobId + "_model_snapshot_" + snapshotId;
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc", documentId);
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc", documentId);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"test-revert-model-snapshot\", \"timestamp\":1541587919000, " +
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", " +
@ -2262,7 +2262,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
client.machineLearning().putJob(new PutJobRequest(job), RequestOptions.DEFAULT);
// Let us index a snapshot
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "doc", documentId);
IndexRequest indexRequest = new IndexRequest(".ml-anomalies-shared", "_doc", documentId);
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.source("{\"job_id\":\"test-update-model-snapshot\", \"timestamp\":1541587919000, " +
"\"description\":\"State persisted due to job close at 2018-11-07T10:51:59+0000\", " +
@ -2475,7 +2475,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
}
public void testGetCalendar() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();
@ -2658,7 +2658,7 @@ public class MlClientDocumentationIT extends ESRestHighLevelClientTestCase {
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
}
public void testPostCalendarEvent() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();

View File

@ -34,19 +34,19 @@ import static org.hamcrest.Matchers.startsWith;
public class CreatedLocationHeaderIT extends ESRestTestCase {
public void testCreate() throws IOException {
locationTestCase("PUT", "test/test/1");
locationTestCase("PUT", "test/_doc/1");
}
public void testIndexWithId() throws IOException {
locationTestCase("PUT", "test/test/1");
locationTestCase("PUT", "test/_doc/1");
}
public void testIndexWithoutId() throws IOException {
locationTestCase("POST", "test/test");
locationTestCase("POST", "test/_doc");
}
public void testUpsert() throws IOException {
Request request = new Request("POST", "test/test/1/_update");
Request request = new Request("POST", "test/_doc/1/_update");
request.setJsonEntity("{"
+ "\"doc\": {\"test\": \"test\"},"
+ "\"doc_as_upsert\": true}");
@ -69,7 +69,7 @@ public class CreatedLocationHeaderIT extends ESRestTestCase {
private void locationTestCase(Response response) throws IOException {
assertEquals(201, response.getStatusLine().getStatusCode());
String location = response.getHeader("Location");
assertThat(location, startsWith("/test/test/"));
assertThat(location, startsWith("/test/_doc/"));
Response getResponse = client().performRequest(new Request("GET", location));
assertEquals(singletonMap("test", "test"), entityAsMap(getResponse).get("_source"));
}

View File

@ -23,10 +23,9 @@ slightly lighter:
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Index
<2> Type
<3> Document id
<4> Disable fetching `_source`.
<5> Disable fetching stored fields.
<2> Document id
<3> Disable fetching `_source`.
<4> Disable fetching stored fields.
include::../execution.asciidoc[]

View File

@ -17,8 +17,7 @@ A +{request}+ requires the following arguments:
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Index
<2> Type
<3> Document id
<2> Document id
[id="{upid}-{api}-request-optional-arguments"]
==== Optional arguments

View File

@ -21,9 +21,8 @@ what to fetch:
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Index
<2> Type
<3> Document id
<4> Add another item to fetch
<2> Document id
<3> Add another item to fetch
==== Optional arguments

View File

@ -93,7 +93,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
}
{
mappingsAndSettings.startObject("mappings");
mappingsAndSettings.startObject("doc");
mappingsAndSettings.startObject("_doc");
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("string");
@ -159,7 +159,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
}
{
mappingsAndSettings.startObject("mappings");
mappingsAndSettings.startObject("doc");
mappingsAndSettings.startObject("_doc");
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("field");
@ -230,7 +230,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
}
{
mappingsAndSettings.startObject("mappings");
mappingsAndSettings.startObject("doc");
mappingsAndSettings.startObject("_doc");
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("key");
@ -333,7 +333,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
mappingsAndSettings.startObject();
{
mappingsAndSettings.startObject("mappings");
mappingsAndSettings.startObject("doc");
mappingsAndSettings.startObject("_doc");
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("field");
@ -401,7 +401,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
mappingsAndSettings.startObject();
{
mappingsAndSettings.startObject("mappings");
mappingsAndSettings.startObject("doc");
mappingsAndSettings.startObject("_doc");
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("field");
@ -489,7 +489,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
bulk.append("{\"index\":{}}\n");
bulk.append("{\"test\":\"test\"}\n");
}
Request bulkRequest = new Request("POST", "/" + index + "_write/doc/_bulk");
Request bulkRequest = new Request("POST", "/" + index + "_write/_doc/_bulk");
bulkRequest.setJsonEntity(bulk.toString());
bulkRequest.addParameter("refresh", "");
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));
@ -619,11 +619,11 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
Map<?, ?> hit = (Map<?, ?>) ((List<?>)(XContentMapValues.extractValue("hits.hits", searchResponse))).get(0);
String docId = (String) hit.get("_id");
Request updateRequest = new Request("POST", "/" + index + "/doc/" + docId + "/_update");
Request updateRequest = new Request("POST", "/" + index + "/_doc/" + docId + "/_update");
updateRequest.setJsonEntity("{ \"doc\" : { \"foo\": \"bar\"}}");
client().performRequest(updateRequest);
Map<String, Object> getRsp = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/doc/" + docId)));
Map<String, Object> getRsp = entityAsMap(client().performRequest(new Request("GET", "/" + index + "/_doc/" + docId)));
Map<?, ?> source = (Map<?, ?>) getRsp.get("_source");
assertTrue("doc does not contain 'foo' key: " + source, source.containsKey("foo"));
@ -676,7 +676,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
* Tests that a single document survives. Super basic smoke test.
*/
public void testSingleDoc() throws IOException {
String docLocation = "/" + index + "/doc/1";
String docLocation = "/" + index + "/_doc/1";
String doc = "{\"test\": \"test\"}";
if (isRunningAgainstOldCluster()) {
@ -863,7 +863,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
}
templateBuilder.endObject();
templateBuilder.startObject("mappings"); {
templateBuilder.startObject("doc"); {
templateBuilder.startObject("_doc"); {
templateBuilder.startObject("_source"); {
templateBuilder.field("enabled", true);
}
@ -973,7 +973,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
int numDocs = between(10, 100);
for (int i = 0; i < numDocs; i++) {
String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v1").endObject());
Request request = new Request("POST", "/" + index + "/doc/" + i);
Request request = new Request("POST", "/" + index + "/_doc/" + i);
request.setJsonEntity(doc);
client().performRequest(request);
if (rarely()) {
@ -986,11 +986,11 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
for (int i = 0; i < numDocs; i++) {
if (randomBoolean()) {
String doc = Strings.toString(JsonXContent.contentBuilder().startObject().field("field", "v2").endObject());
Request request = new Request("POST", "/" + index + "/doc/" + i);
Request request = new Request("POST", "/" + index + "/_doc/" + i);
request.setJsonEntity(doc);
client().performRequest(request);
} else if (randomBoolean()) {
client().performRequest(new Request("DELETE", "/" + index + "/doc/" + i));
client().performRequest(new Request("DELETE", "/" + index + "/_doc/" + i));
liveDocs--;
}
}
@ -1056,7 +1056,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
bulk.append("{\"index\":{\"_id\":\"").append(count + i).append("\"}}\n");
bulk.append("{\"test\":\"test\"}\n");
}
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/doc/_bulk");
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/_doc/_bulk");
writeToRestoredRequest.addParameter("refresh", "true");
writeToRestoredRequest.setJsonEntity(bulk.toString());
assertThat(EntityUtils.toString(client().performRequest(writeToRestoredRequest).getEntity()), containsString("\"errors\":false"));
@ -1088,7 +1088,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
expectedTemplate.put("index_patterns", singletonList("evil_*"));
}
expectedTemplate.put("settings", singletonMap("index", singletonMap("number_of_shards", "1")));
expectedTemplate.put("mappings", singletonMap("doc", singletonMap("_source", singletonMap("enabled", true))));
expectedTemplate.put("mappings", singletonMap("_doc", singletonMap("_source", singletonMap("enabled", true))));
expectedTemplate.put("order", 0);
Map<String, Object> aliases = new HashMap<>();
aliases.put("alias1", emptyMap());
@ -1109,7 +1109,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
logger.info("Indexing {} random documents", count);
for (int i = 0; i < count; i++) {
logger.debug("Indexing document [{}]", i);
Request createDocument = new Request("POST", "/" + index + "/doc/" + i);
Request createDocument = new Request("POST", "/" + index + "/_doc/" + i);
createDocument.setJsonEntity(Strings.toString(docSupplier.apply(i)));
client().performRequest(createDocument);
if (rarely()) {
@ -1134,14 +1134,14 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
infoDoc.field("value", value);
infoDoc.endObject();
// Only create the first version so we know how many documents are created when the index is first created
Request request = new Request("PUT", "/info/doc/" + index + "_" + type);
Request request = new Request("PUT", "/info/_doc/" + index + "_" + type);
request.addParameter("op_type", "create");
request.setJsonEntity(Strings.toString(infoDoc));
client().performRequest(request);
}
private String loadInfoDocument(String type) throws IOException {
Request request = new Request("GET", "/info/doc/" + index + "_" + type);
Request request = new Request("GET", "/info/_doc/" + index + "_" + type);
request.addParameter("filter_path", "_source");
String doc = toStr(client().performRequest(request));
Matcher m = Pattern.compile("\"value\":\"(.+)\"").matcher(doc);

View File

@ -45,7 +45,7 @@ public class IndexingIT extends ESRestTestCase {
private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
for (int i = 0; i < numDocs; i++) {
final int id = idStart + i;
Request request = new Request("PUT", index + "/test/" + id);
Request request = new Request("PUT", index + "/_doc/" + id);
request.setJsonEntity("{\"test\": \"test_" + randomAlphaOfLength(2) + "\"}");
assertOK(client().performRequest(request));
}
@ -284,7 +284,7 @@ public class IndexingIT extends ESRestTestCase {
}
private void assertVersion(final String index, final int docId, final String preference, final int expectedVersion) throws IOException {
Request request = new Request("GET", index + "/test/" + docId);
Request request = new Request("GET", index + "/_doc/" + docId);
request.addParameter("preference", preference);
final Response response = client().performRequest(request);
assertOK(response);

View File

@ -3,8 +3,8 @@
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html",
"methods": ["HEAD"],
"url": {
"path": "/{index}/{type}/{id}",
"paths": ["/{index}/{type}/{id}"],
"path": "/{index}/_doc/{id}",
"paths": ["/{index}/_doc/{id}", "/{index}/{type}/{id}"],
"parts": {
"id": {
"type" : "string",
@ -18,7 +18,6 @@
},
"type": {
"type" : "string",
"required" : true,
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
}
},

View File

@ -3,8 +3,8 @@
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html",
"methods": ["GET"],
"url": {
"path": "/{index}/{type}/{id}",
"paths": ["/{index}/{type}/{id}", "/{index}/_doc/{id}"],
"path": "/{index}/_doc/{id}",
"paths": ["/{index}/_doc/{id}", "/{index}/{type}/{id}"],
"parts": {
"id": {
"type" : "string",

View File

@ -1,10 +1,12 @@
---
"Basic":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
exists:
index: test_1
type: test
id: 1
- is_false: ''
@ -12,7 +14,7 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { "foo": "bar" }
@ -21,7 +23,6 @@
- do:
exists:
index: test_1
type: test
id: 1
- is_true: ''
@ -29,7 +30,6 @@
- do:
exists:
index: test_1
type: test
id: 1
version: 1

View File

@ -0,0 +1,36 @@
---
"Basic":
- do:
exists:
index: test_1
type: test
id: 1
- is_false: ''
- do:
index:
index: test_1
type: test
id: 1
body: { "foo": "bar" }
- is_true: ''
- do:
exists:
index: test_1
type: test
id: 1
- is_true: ''
- do:
exists:
index: test_1
type: test
id: 1
version: 1
- is_true: ''

View File

@ -1,5 +1,8 @@
---
"Routing":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
@ -18,7 +21,7 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
routing: 5
body: { foo: bar }
@ -26,7 +29,6 @@
- do:
exists:
index: test_1
type: test
id: 1
routing: 5
@ -35,7 +37,6 @@
- do:
exists:
index: test_1
type: test
id: 1
- is_false: ''

View File

@ -0,0 +1,41 @@
---
"Routing":
- do:
indices.create:
index: test_1
body:
settings:
index:
number_of_shards: 5
number_of_routing_shards: 5
number_of_replicas: 0
- do:
cluster.health:
wait_for_status: green
- do:
index:
index: test_1
type: test
id: 1
routing: 5
body: { foo: bar }
- do:
exists:
index: test_1
type: test
id: 1
routing: 5
- is_true: ''
- do:
exists:
index: test_1
type: test
id: 1
- is_false: ''

View File

@ -1,5 +1,8 @@
---
"Realtime Refresh":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
@ -17,14 +20,13 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
- do:
exists:
index: test_1
type: test
id: 1
realtime: false
@ -33,7 +35,6 @@
- do:
exists:
index: test_1
type: test
id: 1
realtime: true
@ -42,7 +43,6 @@
- do:
exists:
index: test_1
type: test
id: 1
realtime: false
refresh: true

View File

@ -0,0 +1,50 @@
---
"Realtime Refresh":
- do:
indices.create:
index: test_1
body:
settings:
index:
refresh_interval: -1
number_of_replicas: 0
- do:
cluster.health:
wait_for_status: green
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
exists:
index: test_1
type: test
id: 1
realtime: false
- is_false: ''
- do:
exists:
index: test_1
type: test
id: 1
realtime: true
- is_true: ''
- do:
exists:
index: test_1
type: test
id: 1
realtime: false
refresh: true
- is_true: ''

View File

@ -1,17 +1,19 @@
---
"Client-side default type":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { "foo": "bar" }
- do:
exists:
index: test_1
type: _all
id: 1
- is_true: ''

View File

@ -0,0 +1,17 @@
---
"Client-side default type":
- do:
index:
index: test_1
type: test
id: 1
body: { "foo": "bar" }
- do:
exists:
index: test_1
type: _all
id: 1
- is_true: ''

View File

@ -1,12 +1,16 @@
---
"Basic multi-get":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
index: test_2
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
@ -17,29 +21,23 @@
mget:
body:
docs:
- { _index: test_2, _type: test, _id: 1}
- { _index: test_1, _type: none, _id: 1}
- { _index: test_1, _type: test, _id: 2}
- { _index: test_1, _type: test, _id: 1}
- { _index: test_2, _id: 1}
- { _index: test_1, _id: 2}
- { _index: test_1, _id: 1}
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._type: null }
- match: { docs.0._id: "1" }
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: none }
- match: { docs.1._id: "1" }
- match: { docs.1._type: _doc }
- match: { docs.1._id: "2" }
- is_false: docs.2.found
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "2" }
- is_true: docs.3.found
- match: { docs.3._index: test_1 }
- match: { docs.3._type: test }
- match: { docs.3._id: "1" }
- match: { docs.3._version: 1 }
- match: { docs.3._source: { foo: bar }}
- match: { docs.2._type: _doc }
- match: { docs.2._id: "1" }
- match: { docs.2._version: 1 }
- match: { docs.2._source: { foo: bar }}

View File

@ -1,9 +1,13 @@
---
"Non-existent index":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
@ -11,20 +15,20 @@
mget:
body:
docs:
- { _index: test_2, _type: test, _id: 1}
- { _index: test_2, _id: 1}
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._type: null }
- match: { docs.0._id: "1" }
- do:
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1}
- { _index: test_1, _id: 1}
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._type: _doc }
- match: { docs.0._id: "1" }

View File

@ -1,10 +1,13 @@
---
"Missing metadata":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
@ -13,14 +16,14 @@
mget:
body:
docs:
- { _index: test_1, _type: test}
- { _index: test_1 }
- do:
catch: /action_request_validation_exception.+ index is missing/
mget:
body:
docs:
- { _type: test, _id: 1}
- { _id: 1 }
- do:
catch: /action_request_validation_exception.+ no documents to get/
@ -41,7 +44,7 @@
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._type: _doc }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}

View File

@ -1,15 +1,18 @@
---
"Multi Get with alias that resolves to multiple indices":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
bulk:
refresh: true
body: |
{"index": {"_index": "test_1", "_type": "test", "_id": 1}}
{"index": {"_index": "test_1", "_type": "_doc", "_id": 1}}
{ "foo": "bar" }
{"index": {"_index": "test_2", "_type": "test", "_id": 2}}
{"index": {"_index": "test_2", "_type": "_doc", "_id": 2}}
{ "foo": "bar" }
{"index": {"_index": "test_3", "_type": "test", "_id": 3}}
{"index": {"_index": "test_3", "_type": "_doc", "_id": 3}}
{ "foo": "bar" }
- do:
@ -26,17 +29,17 @@
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1}
- { _index: test_two_and_three, _type: test, _id: 2}
- { _index: test_1, _id: 1}
- { _index: test_two_and_three, _id: 2}
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._type: _doc }
- match: { docs.0._id: "1" }
- is_false: docs.1.found
- match: { docs.1._index: test_two_and_three }
- match: { docs.1._type: test }
- match: { docs.1._type: null }
- match: { docs.1._id: "2" }
- match: { docs.1.error.root_cause.0.type: "illegal_argument_exception" }
- match: { docs.1.error.root_cause.0.reason: "/Alias.\\[test_two_and_three\\].has.more.than.one.indices.associated.with.it.\\[\\[test_[23]{1},.test_[23]{1}\\]\\],.can't.execute.a.single.index.op/" }

View File

@ -1,5 +1,9 @@
---
"IDs":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
index: test_1
@ -7,34 +11,33 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
- do:
index:
index: test_1
type: test
type: _doc
id: 2
body: { foo: baz }
- do:
mget:
index: test_1
type: test
body:
ids: [1, 3]
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._type: _doc }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: test }
- match: { docs.1._type: _doc }
- match: { docs.1._id: "3" }
- do:
@ -45,14 +48,14 @@
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._type: _doc }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}
- is_true: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: test }
- match: { docs.1._type: _doc }
- match: { docs.1._id: "2" }
- match: { docs.1._version: 1 }
- match: { docs.1._source: { foo: baz }}

View File

@ -0,0 +1,45 @@
---
"Basic multi-get":
- do:
indices.create:
index: test_2
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
indices.refresh: {}
- do:
mget:
body:
docs:
- { _index: test_2, _type: test, _id: 1}
- { _index: test_1, _type: none, _id: 1}
- { _index: test_1, _type: test, _id: 2}
- { _index: test_1, _type: test, _id: 1}
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: none }
- match: { docs.1._id: "1" }
- is_false: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "2" }
- is_true: docs.3.found
- match: { docs.3._index: test_1 }
- match: { docs.3._type: test }
- match: { docs.3._id: "1" }
- match: { docs.3._version: 1 }
- match: { docs.3._source: { foo: bar }}

View File

@ -0,0 +1,41 @@
---
"Default index/type":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
index: test_2
- do:
index:
index: test_1
type: _doc
id: 1
body: { foo: bar }
- do:
mget:
index: test_1
body:
docs:
- { _index: test_2, _id: 1}
- { _id: 2}
- { _id: 1}
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: null }
- match: { docs.0._id: "1" }
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: _doc }
- match: { docs.1._id: "2" }
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: _doc }
- match: { docs.2._id: "1" }
- match: { docs.2._version: 1 }
- match: { docs.2._source: { foo: bar }}

View File

@ -0,0 +1,30 @@
---
"Non-existent index":
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
mget:
body:
docs:
- { _index: test_2, _type: test, _id: 1}
- is_false: docs.0.found
- match: { docs.0._index: test_2 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- do:
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1}
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }

View File

@ -0,0 +1,47 @@
---
"Missing metadata":
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
catch: /action_request_validation_exception.+ id is missing/
mget:
body:
docs:
- { _index: test_1, _type: test}
- do:
catch: /action_request_validation_exception.+ index is missing/
mget:
body:
docs:
- { _type: test, _id: 1}
- do:
catch: /action_request_validation_exception.+ no documents to get/
mget:
body:
docs: []
- do:
catch: /action_request_validation_exception.+ no documents to get/
mget:
body: {}
- do:
mget:
body:
docs:
- { _index: test_1, _id: 1}
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}

View File

@ -1,12 +1,15 @@
---
"Stored fields":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
index: test_1
body:
mappings:
test:
_doc:
properties:
foo:
type: keyword
@ -18,14 +21,13 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
- do:
mget:
index: test_1
type: test
body:
docs:
- { _id: 1 }
@ -48,7 +50,6 @@
- do:
mget:
index: test_1
type: test
stored_fields: foo
body:
docs:
@ -72,7 +73,6 @@
- do:
mget:
index: test_1
type: test
stored_fields: [foo]
body:
docs:
@ -96,7 +96,6 @@
- do:
mget:
index: test_1
type: test
stored_fields: [foo, _source]
body:
docs:

View File

@ -0,0 +1,42 @@
---
"Multi Get with alias that resolves to multiple indices":
- do:
bulk:
refresh: true
body: |
{"index": {"_index": "test_1", "_type": "test", "_id": 1}}
{ "foo": "bar" }
{"index": {"_index": "test_2", "_type": "test", "_id": 2}}
{ "foo": "bar" }
{"index": {"_index": "test_3", "_type": "test", "_id": 3}}
{ "foo": "bar" }
- do:
indices.put_alias:
index: test_2
name: test_two_and_three
- do:
indices.put_alias:
index: test_3
name: test_two_and_three
- do:
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1}
- { _index: test_two_and_three, _type: test, _id: 2}
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- is_false: docs.1.found
- match: { docs.1._index: test_two_and_three }
- match: { docs.1._type: test }
- match: { docs.1._id: "2" }
- match: { docs.1.error.root_cause.0.type: "illegal_argument_exception" }
- match: { docs.1.error.root_cause.0.reason: "/Alias.\\[test_two_and_three\\].has.more.than.one.indices.associated.with.it.\\[\\[test_[23]{1},.test_[23]{1}\\]\\],.can't.execute.a.single.index.op/" }

View File

@ -0,0 +1,72 @@
---
"IDs":
- do:
indices.create:
index: test_1
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
index:
index: test_1
type: test
id: 2
body: { foo: baz }
- do:
mget:
index: test_1
type: test
body:
ids: [1, 3]
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}
- is_false: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: test }
- match: { docs.1._id: "3" }
- do:
mget:
index: test_1
body:
ids: [1, 2]
- is_true: docs.0.found
- match: { docs.0._index: test_1 }
- match: { docs.0._type: test }
- match: { docs.0._id: "1" }
- match: { docs.0._version: 1 }
- match: { docs.0._source: { foo: bar }}
- is_true: docs.1.found
- match: { docs.1._index: test_1 }
- match: { docs.1._type: test }
- match: { docs.1._id: "2" }
- match: { docs.1._version: 1 }
- match: { docs.1._source: { foo: baz }}
- do:
catch: /action_request_validation_exception.+ no documents to get/
mget:
index: test_1
body:
ids: []
- do:
catch: /action_request_validation_exception.+ no documents to get/
mget:
index: test_1
body: {}

View File

@ -0,0 +1,119 @@
---
"Stored fields":
- do:
indices.create:
index: test_1
body:
mappings:
test:
properties:
foo:
type: keyword
store: true
count:
type: integer
store: true
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
mget:
index: test_1
type: test
body:
docs:
- { _id: 1 }
- { _id: 1, stored_fields: foo }
- { _id: 1, stored_fields: [foo] }
- { _id: 1, stored_fields: [foo, _source] }
- is_false: docs.0.fields
- match: { docs.0._source: { foo: bar }}
- match: { docs.1.fields.foo: [bar] }
- is_false: docs.1._source
- match: { docs.2.fields.foo: [bar] }
- is_false: docs.2._source
- match: { docs.3.fields.foo: [bar] }
- match: { docs.3._source: { foo: bar }}
- do:
mget:
index: test_1
type: test
stored_fields: foo
body:
docs:
- { _id: 1 }
- { _id: 1, stored_fields: foo }
- { _id: 1, stored_fields: [foo] }
- { _id: 1, stored_fields: [foo, _source] }
- match: { docs.0.fields.foo: [bar] }
- is_false: docs.0._source
- match: { docs.1.fields.foo: [bar] }
- is_false: docs.1._source
- match: { docs.2.fields.foo: [bar] }
- is_false: docs.2._source
- match: { docs.3.fields.foo: [bar] }
- match: { docs.3._source: { foo: bar }}
- do:
mget:
index: test_1
type: test
stored_fields: [foo]
body:
docs:
- { _id: 1 }
- { _id: 1, stored_fields: foo }
- { _id: 1, stored_fields: [foo] }
- { _id: 1, stored_fields: [foo, _source] }
- match: { docs.0.fields.foo: [bar] }
- is_false: docs.0._source
- match: { docs.1.fields.foo: [bar] }
- is_false: docs.1._source
- match: { docs.2.fields.foo: [bar] }
- is_false: docs.2._source
- match: { docs.3.fields.foo: [bar] }
- match: { docs.3._source: { foo: bar }}
- do:
mget:
index: test_1
type: test
stored_fields: [foo, _source]
body:
docs:
- { _id: 1 }
- { _id: 1, stored_fields: foo }
- { _id: 1, stored_fields: [foo] }
- { _id: 1, stored_fields: [foo, _source] }
- match: { docs.0.fields.foo: [bar] }
- match: { docs.0._source: { foo: bar }}
- match: { docs.1.fields.foo: [bar] }
- is_false: docs.1._source
- match: { docs.2.fields.foo: [bar] }
- is_false: docs.2._source
- match: { docs.3.fields.foo: [bar] }
- match: { docs.3._source: { foo: bar }}

View File

@ -1,5 +1,8 @@
---
"Routing":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
@ -18,7 +21,7 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
routing: 5
body: { foo: bar }
@ -26,7 +29,6 @@
- do:
mget:
index: test_1
type: test
stored_fields: [_routing]
body:
docs:
@ -39,6 +41,6 @@
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._type: _doc }
- match: { docs.2._id: "1" }
- match: { docs.2._routing: "5" }

View File

@ -0,0 +1,44 @@
---
"Routing":
- do:
indices.create:
index: test_1
body:
settings:
index:
number_of_shards: 5
number_of_routing_shards: 5
number_of_replicas: 0
- do:
cluster.health:
wait_for_status: green
- do:
index:
index: test_1
type: test
id: 1
routing: 5
body: { foo: bar }
- do:
mget:
index: test_1
type: test
stored_fields: [_routing]
body:
docs:
- { _id: 1 }
- { _id: 1, routing: 4 }
- { _id: 1, routing: 5 }
- is_false: docs.0.found
- is_false: docs.1.found
- is_true: docs.2.found
- match: { docs.2._index: test_1 }
- match: { docs.2._type: test }
- match: { docs.2._id: "1" }
- match: { docs.2._routing: "5" }

View File

@ -1,5 +1,8 @@
---
"Realtime Refresh":
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
indices.create:
@ -17,14 +20,13 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
- do:
mget:
index: test_1
type: test
realtime: false
body:
ids: [1]
@ -34,7 +36,6 @@
- do:
mget:
index: test_1
type: test
realtime: true
body:
ids: [1]
@ -44,7 +45,6 @@
- do:
mget:
index: test_1
type: test
realtime: false
refresh: true
body:

View File

@ -0,0 +1,53 @@
---
"Realtime Refresh":
- do:
indices.create:
index: test_1
body:
settings:
index:
refresh_interval: -1
number_of_replicas: 0
- do:
cluster.health:
wait_for_status: green
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
mget:
index: test_1
type: test
realtime: false
body:
ids: [1]
- is_false: docs.0.found
- do:
mget:
index: test_1
type: test
realtime: true
body:
ids: [1]
- is_true: docs.0.found
- do:
mget:
index: test_1
type: test
realtime: false
refresh: true
body:
ids: [1]
- is_true: docs.0.found

View File

@ -1,14 +1,18 @@
setup:
- skip:
version: " - 6.99.99"
reason: types are required in requests before 7.0.0
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1 }
- do:
index:
index: test_1
type: test
type: _doc
id: 2
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1 }
@ -19,8 +23,8 @@ setup:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: false }
- { _index: "test_1", _type: "test", _id: "2", _source: true }
- { _index: "test_1", _id: "1", _source: false }
- { _index: "test_1", _id: "2", _source: true }
- match: { docs.0._id: "1" }
- is_false: docs.0._source
@ -34,8 +38,8 @@ setup:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: include.field1 }
- { _index: "test_1", _type: "test", _id: "2", _source: [ include.field1 ] }
- { _index: "test_1", _id: "1", _source: include.field1 }
- { _index: "test_1", _id: "2", _source: [ include.field1 ] }
- match: { docs.0._source: { include: { field1: v1 }} }
- match: { docs.1._source: { include: { field1: v1 }} }
@ -48,8 +52,8 @@ setup:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: { include: include.field1 } }
- { _index: "test_1", _type: "test", _id: "2", _source: { include: [ include.field1 ] } }
- { _index: "test_1", _id: "1", _source: { include: include.field1 } }
- { _index: "test_1", _id: "2", _source: { include: [ include.field1 ] } }
- match: { docs.0._source: { include: { field1: v1 }} }
- match: { docs.1._source: { include: { field1: v1 }} }
@ -61,7 +65,7 @@ setup:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: { include: [ include ], exclude: [ "*.field2" ] } }
- { _index: "test_1", _id: "1", _source: { include: [ include ], exclude: [ "*.field2" ] } }
- match: { docs.0._source: { include: { field1: v1 }} }

View File

@ -0,0 +1,119 @@
setup:
- do:
index:
index: test_1
type: test
id: 1
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1 }
- do:
index:
index: test_1
type: test
id: 2
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1 }
---
"Source filtering - true/false":
- do:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: false }
- { _index: "test_1", _type: "test", _id: "2", _source: true }
- match: { docs.0._id: "1" }
- is_false: docs.0._source
- match: { docs.1._id: "2" }
- is_true: docs.1._source
---
"Source filtering - include field":
- do:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: include.field1 }
- { _index: "test_1", _type: "test", _id: "2", _source: [ include.field1 ] }
- match: { docs.0._source: { include: { field1: v1 }} }
- match: { docs.1._source: { include: { field1: v1 }} }
---
"Source filtering - include nested field":
- do:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: { include: include.field1 } }
- { _index: "test_1", _type: "test", _id: "2", _source: { include: [ include.field1 ] } }
- match: { docs.0._source: { include: { field1: v1 }} }
- match: { docs.1._source: { include: { field1: v1 }} }
---
"Source filtering - exclude field":
- do:
mget:
body:
docs:
- { _index: "test_1", _type: "test", _id: "1", _source: { include: [ include ], exclude: [ "*.field2" ] } }
- match: { docs.0._source: { include: { field1: v1 }} }
---
"Source filtering - ids and true/false":
- do:
mget:
_source: false
index: test_1
body: { ids: [ 1,2 ] }
- is_false: docs.0._source
- is_false: docs.1._source
- do:
mget:
_source: true
index: test_1
body: { ids: [ 1,2 ] }
- is_true: docs.0._source
- is_true: docs.1._source
---
"Source filtering - ids and include field":
- do:
mget:
_source: include.field1
index: test_1
body: { ids: [ 1,2 ] }
- match: { docs.0._source: { include: { field1: v1 }} }
- match: { docs.1._source: { include: { field1: v1 }} }
---
"Source filtering - ids and include nested field":
- do:
mget:
_source_includes: "include.field1,count"
index: test_1
body: { ids: [ 1,2 ] }
- match: { docs.0._source: { include: { field1: v1 }, count: 1} }
- match: { docs.1._source: { include: { field1: v1 }, count: 1} }
---
"Source filtering - ids and exclude field":
- do:
mget:
_source_includes: include
_source_excludes: "*.field2"
index: test_1
body: { ids: [ 1,2 ] }
- match: { docs.0._source: { include: { field1: v1 } } }
- match: { docs.1._source: { include: { field1: v1 } } }

View File

@ -1,7 +1,6 @@
---
"Deprecated parameters should fail in Multi Get query":
- skip:
version: " - 6.99.99"
reason: _version, _routing are removed starting from 7.0, their equivalents without underscore are used instead
@ -10,14 +9,14 @@
- do:
index:
index: test_1
type: test
type: _doc
id: 1
body: { foo: bar }
- do:
index:
index: test_1
type: test
type: _doc
id: 2
body: { foo: baz }
@ -26,13 +25,13 @@
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1, _routing : test1 }
- { _index: test_1, _type: test, _id: 2, _routing : test1 }
- { _index: test_1, _id: 1, _routing : test1 }
- { _index: test_1, _id: 2, _routing : test1 }
- do:
catch: bad_request
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1, _version : 1 }
- { _index: test_1, _type: test, _id: 2, _version : 1 }
- { _index: test_1, _id: 1, _version : 1 }
- { _index: test_1, _id: 2, _version : 1 }

View File

@ -0,0 +1,38 @@
---
"Deprecated parameters should fail in Multi Get query":
- skip:
version: " - 6.99.99"
reason: _version, _routing are removed starting from 7.0, their equivalents without underscore are used instead
features: "warnings"
- do:
index:
index: test_1
type: test
id: 1
body: { foo: bar }
- do:
index:
index: test_1
type: test
id: 2
body: { foo: baz }
- do:
catch: bad_request
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1, _routing : test1 }
- { _index: test_1, _type: test, _id: 2, _routing : test1 }
- do:
catch: bad_request
mget:
body:
docs:
- { _index: test_1, _type: test, _id: 1, _version : 1 }
- { _index: test_1, _type: test, _id: 2, _version : 1 }

View File

@ -30,6 +30,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import java.io.IOException;
@ -66,16 +67,15 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
private long version = Versions.MATCH_ANY;
public GetRequest() {
type = "_all";
type = MapperService.SINGLE_MAPPING_NAME;
}
/**
* Constructs a new get request against the specified index. The {@link #type(String)} and {@link #id(String)}
* must be set.
* Constructs a new get request against the specified index. The {@link #id(String)} must also be set.
*/
public GetRequest(String index) {
super(index);
this.type = "_all";
this.type = MapperService.SINGLE_MAPPING_NAME;
}
/**
@ -84,13 +84,28 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
* @param index The index to get the document from
* @param type The type of the document
* @param id The id of the document
*
* @deprecated Types are in the process of being removed, use {@link GetRequest(String, String)} instead.
*/
@Deprecated
public GetRequest(String index, String type, String id) {
super(index);
this.type = type;
this.id = id;
}
/**
* Constructs a new get request against the specified index and document ID.
*
* @param index The index to get the document from
* @param id The id of the document
*/
public GetRequest(String index, String id) {
super(index);
this.id = id;
this.type = MapperService.SINGLE_MAPPING_NAME;
}
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validateNonNullIndex();
@ -112,10 +127,13 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
/**
* Sets the type of the document to fetch.
*
* @deprecated Types are in the process of being removed.
*/
@Deprecated
public GetRequest type(@Nullable String type) {
if (type == null) {
type = "_all";
type = MapperService.SINGLE_MAPPING_NAME;
}
this.type = type;
return this;
@ -148,6 +166,10 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
return this;
}
/**
* @deprecated Types are in the process of being removed.
*/
@Deprecated
public String type() {
return type;
}

View File

@ -89,13 +89,21 @@ public class MultiGetRequest extends ActionRequest
* @param index The index name
* @param type The type (can be null)
* @param id The id
*
* @deprecated Types are in the process of being removed, use {@link Item(String, String) instead}.
*/
@Deprecated
public Item(String index, @Nullable String type, String id) {
this.index = index;
this.type = type;
this.id = id;
}
public Item(String index, String id) {
this.index = index;
this.id = id;
}
public String index() {
return this.index;
}
@ -119,11 +127,6 @@ public class MultiGetRequest extends ActionRequest
return this.type;
}
public Item type(String type) {
this.type = type;
return this;
}
public String id() {
return this.id;
}
@ -285,11 +288,21 @@ public class MultiGetRequest extends ActionRequest
return this;
}
/**
* @deprecated Types are in the process of being removed, use
* {@link MultiGetRequest#add(String, String)} instead.
*/
@Deprecated
public MultiGetRequest add(String index, @Nullable String type, String id) {
items.add(new Item(index, type, id));
return this;
}
public MultiGetRequest add(String index, String id) {
items.add(new Item(index, id));
return this;
}
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;

View File

@ -19,12 +19,15 @@
package org.elasticsearch.rest.action.document;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
@ -41,6 +44,10 @@ import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestGetAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(RestGetAction.class));
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " +
"document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead.";
public RestGetAction(final Settings settings, final RestController controller) {
super(settings);
@ -55,9 +62,12 @@ public class RestGetAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final GetRequest getRequest = new GetRequest(request.param("index"),
request.param("type"),
request.param("id"));
String type = request.param("type");
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
}
final GetRequest getRequest = new GetRequest(request.param("index"), type, request.param("id"));
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.routing(request.param("routing"));
getRequest.preference(request.param("preference"));

View File

@ -19,9 +19,11 @@
package org.elasticsearch.rest.action.document;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.get.MultiGetRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
@ -36,6 +38,10 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestMultiGetAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(RestMultiGetAction.class));
static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" +
" Specifying types in multi get requests is deprecated.";
private final boolean allowExplicitIndex;
@ -58,6 +64,10 @@ public class RestMultiGetAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
if (request.param("type") != null) {
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
}
MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
multiGetRequest.preference(request.param("preference"));
@ -78,6 +88,13 @@ public class RestMultiGetAction extends BaseRestHandler {
request.param("routing"), parser, allowExplicitIndex);
}
for (MultiGetRequest.Item item : multiGetRequest.getItems()) {
if (item.type() != null) {
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
break;
}
}
return channel -> client.multiGet(multiGetRequest, new RestToXContentListener<>(channel));
}
}

View File

@ -0,0 +1,56 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest.action.document;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestActionTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.junit.Before;
public class RestGetActionTests extends RestActionTestCase {
@Before
public void setUpAction() {
new RestGetAction(Settings.EMPTY, controller());
}
public void testTypeInPathWithGet() {
FakeRestRequest.Builder deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry())
.withPath("/some_index/some_type/some_id");
dispatchRequest(deprecatedRequest.withMethod(Method.GET).build());
assertWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE);
FakeRestRequest.Builder validRequest = new FakeRestRequest.Builder(xContentRegistry())
.withPath("/some_index/_doc/some_id");
dispatchRequest(validRequest.withMethod(Method.GET).build());
}
public void testTypeInPathWithHead() {
FakeRestRequest.Builder deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry())
.withPath("/some_index/some_type/some_id");
dispatchRequest(deprecatedRequest.withMethod(Method.HEAD).build());
assertWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE);
FakeRestRequest.Builder validRequest = new FakeRestRequest.Builder(xContentRegistry())
.withPath("/some_index/_doc/some_id");
dispatchRequest(validRequest.withMethod(Method.HEAD).build());
}
}

View File

@ -0,0 +1,77 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest.action.document;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestActionTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.junit.Before;
public class RestMultiGetActionTests extends RestActionTestCase {
@Before
public void setUpAction() {
new RestMultiGetAction(Settings.EMPTY, controller());
}
public void testTypeInPath() {
RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(Method.GET)
.withPath("some_index/some_type/_mget")
.build();
dispatchRequest(deprecatedRequest);
assertWarnings(RestMultiGetAction.TYPES_DEPRECATION_MESSAGE);
RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(Method.GET)
.withPath("some_index/_mget")
.build();
dispatchRequest(validRequest);
}
public void testTypeInBody() throws Exception {
XContentBuilder content = XContentFactory.jsonBuilder().startObject()
.startArray("docs")
.startObject()
.field("_index", "some_index")
.field("_type", "_doc")
.field("_id", "2")
.endObject()
.startObject()
.field("_index", "test")
.field("_id", "2")
.endObject()
.endArray()
.endObject();
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withPath("_mget")
.withContent(BytesReference.bytes(content), XContentType.JSON)
.build();
dispatchRequest(request);
assertWarnings(RestMultiGetAction.TYPES_DEPRECATION_MESSAGE);
}
}

View File

@ -80,7 +80,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
* Tests that a single document survives. Super basic smoke test.
*/
public void testSingleDoc() throws IOException {
String docLocation = "/testsingledoc/doc/1";
String docLocation = "/testsingledoc/_doc/1";
String doc = "{\"test\": \"test\"}";
if (isRunningAgainstOldCluster()) {
@ -252,7 +252,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
// index documents for the rollup job
final StringBuilder bulk = new StringBuilder();
for (int i = 0; i < numDocs; i++) {
bulk.append("{\"index\":{\"_index\":\"rollup-docs\",\"_type\":\"doc\"}}\n");
bulk.append("{\"index\":{\"_index\":\"rollup-docs\",\"_type\":\"_doc\"}}\n");
String date = String.format(Locale.ROOT, "%04d-01-01T00:%02d:00Z", year, i);
bulk.append("{\"timestamp\":\"").append(date).append("\",\"value\":").append(i).append("}\n");
}

View File

@ -63,7 +63,7 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
assertNotNull(token);
assertTokenWorks(token);
Request indexRequest1 = new Request("PUT", "token_backwards_compatibility_it/doc/old_cluster_token1");
Request indexRequest1 = new Request("PUT", "token_backwards_compatibility_it/_doc/old_cluster_token1");
indexRequest1.setJsonEntity(
"{\n" +
" \"token\": \"" + token + "\"\n" +
@ -77,7 +77,7 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
token = (String) responseMap.get("access_token");
assertNotNull(token);
assertTokenWorks(token);
Request indexRequest2 = new Request("PUT", "token_backwards_compatibility_it/doc/old_cluster_token2");
Request indexRequest2 = new Request("PUT", "token_backwards_compatibility_it/_doc/old_cluster_token2");
indexRequest2.setJsonEntity(
"{\n" +
" \"token\": \"" + token + "\"\n" +
@ -88,7 +88,7 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
public void testTokenWorksInMixedOrUpgradedCluster() throws Exception {
assumeTrue("this test should only run against the mixed or upgraded cluster",
CLUSTER_TYPE == ClusterType.MIXED || CLUSTER_TYPE == ClusterType.UPGRADED);
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/doc/old_cluster_token1"));
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/_doc/old_cluster_token1"));
assertOK(getResponse);
Map<String, Object> source = (Map<String, Object>) entityAsMap(getResponse).get("_source");
assertTokenWorks((String) source.get("token"));
@ -97,7 +97,7 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
public void testMixedCluster() throws Exception {
assumeTrue("this test should only run against the mixed cluster", CLUSTER_TYPE == ClusterType.MIXED);
assumeTrue("the master must be on the latest version before we can write", isMasterOnLatestVersion());
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/doc/old_cluster_token2"));
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/_doc/old_cluster_token2"));
Map<String, Object> source = (Map<String, Object>) entityAsMap(getResponse).get("_source");
final String token = (String) source.get("token");
assertTokenWorks(token);
@ -146,7 +146,7 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
public void testUpgradedCluster() throws Exception {
assumeTrue("this test should only run against the mixed cluster", CLUSTER_TYPE == ClusterType.UPGRADED);
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/doc/old_cluster_token2"));
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/_doc/old_cluster_token2"));
assertOK(getResponse);
Map<String, Object> source = (Map<String, Object>) entityAsMap(getResponse).get("_source");
final String token = (String) source.get("token");
@ -159,7 +159,7 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
assertOK(invalidationResponse);
assertTokenDoesNotWork(token);
getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/doc/old_cluster_token1"));
getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/_doc/old_cluster_token1"));
source = (Map<String, Object>) entityAsMap(getResponse).get("_source");
final String workingToken = (String) source.get("token");
assertTokenWorks(workingToken);

View File

@ -42,7 +42,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
@Before
public void startWatcher() throws Exception {
Request createAllowedDoc = new Request("PUT", "/my_test_index/doc/1");
Request createAllowedDoc = new Request("PUT", "/my_test_index/_doc/1");
createAllowedDoc.setJsonEntity("{ \"value\" : \"15\" }");
createAllowedDoc.addParameter("refresh", "true");
adminClient().performRequest(createAllowedDoc);
@ -51,7 +51,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
adminClient().performRequest(new Request("DELETE", ".watcher-history-*"));
// create one document in this index, so we can test in the YAML tests, that the index cannot be accessed
Request createNotAllowedDoc = new Request("PUT", "/index_not_allowed_to_read/doc/1");
Request createNotAllowedDoc = new Request("PUT", "/index_not_allowed_to_read/_doc/1");
createNotAllowedDoc.setJsonEntity("{\"foo\":\"bar\"}");
adminClient().performRequest(createNotAllowedDoc);
@ -211,7 +211,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));
ObjectPath getObjectPath = ObjectPath.createFromResponse(client().performRequest(new Request("GET", "/my_test_index/doc/my-id")));
ObjectPath getObjectPath = ObjectPath.createFromResponse(client().performRequest(new Request("GET", "/my_test_index/_doc/my-id")));
String value = getObjectPath.evaluate("_source.hits.hits.0._source.value");
assertThat(value, is("15"));
}
@ -239,7 +239,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
getWatchHistoryEntry(watchId);
Response response = adminClient().performRequest(new Request("HEAD", "/my_test_index/doc/some-id"));
Response response = adminClient().performRequest(new Request("HEAD", "/my_test_index/_doc/some-id"));
assertThat(response.getStatusLine().getStatusCode(), is(404));
}
@ -262,7 +262,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));
ObjectPath getObjectPath = ObjectPath.createFromResponse(client().performRequest(new Request("GET", "/my_test_index/doc/my-id")));
ObjectPath getObjectPath = ObjectPath.createFromResponse(client().performRequest(new Request("GET", "/my_test_index/_doc/my-id")));
String spam = getObjectPath.evaluate("_source.spam");
assertThat(spam, is("eggs"));
}
@ -286,7 +286,7 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));
Response response = adminClient().performRequest(new Request("HEAD", "/index_not_allowed_to_read/doc/my-id"));
Response response = adminClient().performRequest(new Request("HEAD", "/index_not_allowed_to_read/_doc/my-id"));
assertThat(response.getStatusLine().getStatusCode(), is(404));
}