Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testBulkProcessorConcurrentRequests() throws Exception {
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
Expand Down Expand Up @@ -240,12 +240,12 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception
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"));
}
}
Expand All @@ -262,7 +262,7 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception
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
Expand Down Expand Up @@ -330,12 +330,12 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
.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));
Expand All @@ -346,7 +346,7 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
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)));
}
}
Expand All @@ -359,18 +359,18 @@ private Matcher<SearchHit>[] expectedIds(int numDocs) {
.<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;
}
Expand All @@ -396,15 +396,15 @@ private static BytesArray bytesBulkRequest(String localIndex, String localType,
}

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) {
assertThat(bulkItemResponses.size(), is(numDocs));
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));
Expand All @@ -416,7 +416,7 @@ private static void assertMultiGetResponse(MultiGetResponse multiGetResponse, in
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++)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
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(
Expand Down Expand Up @@ -144,9 +143,9 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,46 +175,46 @@ public void testDelete() throws IOException {

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");
index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON);
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");
index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON);
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));
}
}
Expand Down Expand Up @@ -245,15 +245,15 @@ public void testSourceDoesNotExist() throws IOException {
);
}
{
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));
}
}

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());
Expand All @@ -266,7 +266,7 @@ public void testGet() throws IOException {
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());
Expand All @@ -275,7 +275,7 @@ public void testGet() throws IOException {
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);
}
Expand All @@ -289,7 +289,7 @@ public void testGet() throws IOException {
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());
Expand All @@ -300,7 +300,7 @@ public void testGet() throws IOException {
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());
Expand All @@ -312,7 +312,7 @@ public void testGet() throws IOException {
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 {
Expand All @@ -334,23 +334,23 @@ public void testGet() throws IOException {
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());

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());
Expand All @@ -366,8 +366,8 @@ public void testMultiGet() throws IOException {
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);

Expand Down Expand Up @@ -789,7 +789,7 @@ public void testUpdateByQuery() throws Exception {
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"))
);
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ public void testUrlEncode() throws IOException {
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());
Expand All @@ -1077,7 +1077,7 @@ public void testUrlEncode() throws IOException {
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());
Expand All @@ -1101,7 +1101,7 @@ public void testParamsEncode() throws IOException {
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());
Expand Down
Loading