|
@@ -65,6 +65,10 @@ import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
|
|
import org.elasticsearch.index.reindex.UpdateByQueryAction;
|
|
|
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
|
+import org.elasticsearch.rest.action.document.RestDeleteAction;
|
|
|
+import org.elasticsearch.rest.action.document.RestGetAction;
|
|
|
+import org.elasticsearch.rest.action.document.RestMultiGetAction;
|
|
|
+import org.elasticsearch.rest.action.document.RestUpdateAction;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.script.ScriptType;
|
|
|
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
|
@@ -173,6 +177,23 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testDeleteWithTypes() throws IOException {
|
|
|
+ String docId = "id";
|
|
|
+ highLevelClient().index(new IndexRequest("index", "type", docId)
|
|
|
+ .source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT);
|
|
|
+
|
|
|
+ DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId);
|
|
|
+ DeleteResponse deleteResponse = execute(deleteRequest,
|
|
|
+ highLevelClient()::delete,
|
|
|
+ highLevelClient()::deleteAsync,
|
|
|
+ expectWarnings(RestDeleteAction.TYPES_DEPRECATION_MESSAGE));
|
|
|
+
|
|
|
+ assertEquals("index", deleteResponse.getIndex());
|
|
|
+ assertEquals("type", deleteResponse.getType());
|
|
|
+ assertEquals(docId, deleteResponse.getId());
|
|
|
+ assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
|
|
|
+ }
|
|
|
+
|
|
|
public void testExists() throws IOException {
|
|
|
{
|
|
|
GetRequest getRequest = new GetRequest("index", "id");
|
|
@@ -331,6 +352,29 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testGetWithTypes() throws IOException {
|
|
|
+ String document = "{\"field\":\"value\"}";
|
|
|
+ IndexRequest index = new IndexRequest("index", "type", "id");
|
|
|
+ index.source(document, XContentType.JSON);
|
|
|
+ index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
|
|
|
+ highLevelClient().index(index, RequestOptions.DEFAULT);
|
|
|
+
|
|
|
+ GetRequest getRequest = new GetRequest("index", "type", "id");
|
|
|
+ GetResponse getResponse = execute(getRequest,
|
|
|
+ highLevelClient()::get,
|
|
|
+ highLevelClient()::getAsync,
|
|
|
+ expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
|
|
|
+
|
|
|
+ assertEquals("index", getResponse.getIndex());
|
|
|
+ assertEquals("type", getResponse.getType());
|
|
|
+ assertEquals("id", getResponse.getId());
|
|
|
+
|
|
|
+ assertTrue(getResponse.isExists());
|
|
|
+ assertFalse(getResponse.isSourceEmpty());
|
|
|
+ assertEquals(1L, getResponse.getVersion());
|
|
|
+ assertEquals(document, getResponse.getSourceAsString());
|
|
|
+ }
|
|
|
+
|
|
|
public void testMultiGet() throws IOException {
|
|
|
{
|
|
|
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
|
@@ -387,6 +431,36 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testMultiGetWithTypes() throws IOException {
|
|
|
+ BulkRequest bulk = new BulkRequest();
|
|
|
+ bulk.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
|
|
|
+ bulk.add(new IndexRequest("index", "type", "id1")
|
|
|
+ .source("{\"field\":\"value1\"}", XContentType.JSON));
|
|
|
+ bulk.add(new IndexRequest("index", "type", "id2")
|
|
|
+ .source("{\"field\":\"value2\"}", XContentType.JSON));
|
|
|
+
|
|
|
+ highLevelClient().bulk(bulk, RequestOptions.DEFAULT);
|
|
|
+ MultiGetRequest multiGetRequest = new MultiGetRequest();
|
|
|
+ multiGetRequest.add("index", "id1");
|
|
|
+ multiGetRequest.add("index", "type", "id2");
|
|
|
+
|
|
|
+ MultiGetResponse response = execute(multiGetRequest,
|
|
|
+ highLevelClient()::mget,
|
|
|
+ highLevelClient()::mgetAsync,
|
|
|
+ expectWarnings(RestMultiGetAction.TYPES_DEPRECATION_MESSAGE));
|
|
|
+ assertEquals(2, response.getResponses().length);
|
|
|
+
|
|
|
+ GetResponse firstResponse = response.getResponses()[0].getResponse();
|
|
|
+ assertEquals("index", firstResponse.getIndex());
|
|
|
+ assertEquals("type", firstResponse.getType());
|
|
|
+ assertEquals("id1", firstResponse.getId());
|
|
|
+
|
|
|
+ GetResponse secondResponse = response.getResponses()[1].getResponse();
|
|
|
+ assertEquals("index", secondResponse.getIndex());
|
|
|
+ assertEquals("type", secondResponse.getType());
|
|
|
+ assertEquals("id2", secondResponse.getId());
|
|
|
+ }
|
|
|
+
|
|
|
public void testIndex() throws IOException {
|
|
|
final XContentType xContentType = randomFrom(XContentType.values());
|
|
|
{
|
|
@@ -492,7 +566,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
|
|
|
public void testUpdate() throws IOException {
|
|
|
{
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "does_not_exist");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "does_not_exist");
|
|
|
updateRequest.doc(singletonMap("field", "value"), randomFrom(XContentType.values()));
|
|
|
|
|
|
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () ->
|
|
@@ -507,14 +581,14 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
|
|
assertEquals(RestStatus.CREATED, indexResponse.status());
|
|
|
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "id");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "id");
|
|
|
updateRequest.doc(singletonMap("field", "updated"), randomFrom(XContentType.values()));
|
|
|
|
|
|
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
|
|
assertEquals(RestStatus.OK, updateResponse.status());
|
|
|
assertEquals(indexResponse.getVersion() + 1, updateResponse.getVersion());
|
|
|
|
|
|
- UpdateRequest updateRequestConflict = new UpdateRequest("index", "_doc", "id");
|
|
|
+ UpdateRequest updateRequestConflict = new UpdateRequest("index", "id");
|
|
|
updateRequestConflict.doc(singletonMap("field", "with_version_conflict"), randomFrom(XContentType.values()));
|
|
|
updateRequestConflict.version(indexResponse.getVersion());
|
|
|
|
|
@@ -530,7 +604,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
|
|
assertEquals(RestStatus.CREATED, indexResponse.status());
|
|
|
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "with_script");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "with_script");
|
|
|
Script script = new Script(ScriptType.INLINE, "painless", "ctx._source.counter += params.count", singletonMap("count", 8));
|
|
|
updateRequest.script(script);
|
|
|
updateRequest.fetchSource(true);
|
|
@@ -551,7 +625,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
assertEquals(RestStatus.CREATED, indexResponse.status());
|
|
|
assertEquals(12L, indexResponse.getVersion());
|
|
|
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "with_doc");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "with_doc");
|
|
|
updateRequest.doc(singletonMap("field_2", "two"), randomFrom(XContentType.values()));
|
|
|
updateRequest.fetchSource("field_*", "field_3");
|
|
|
|
|
@@ -573,7 +647,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
assertEquals(RestStatus.CREATED, indexResponse.status());
|
|
|
assertEquals(1L, indexResponse.getVersion());
|
|
|
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "noop");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "noop");
|
|
|
updateRequest.doc(singletonMap("field", "value"), randomFrom(XContentType.values()));
|
|
|
|
|
|
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
|
@@ -589,7 +663,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
assertEquals(2L, updateResponse.getVersion());
|
|
|
}
|
|
|
{
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "with_upsert");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "with_upsert");
|
|
|
updateRequest.upsert(singletonMap("doc_status", "created"));
|
|
|
updateRequest.doc(singletonMap("doc_status", "updated"));
|
|
|
updateRequest.fetchSource(true);
|
|
@@ -604,7 +678,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
assertEquals("created", getResult.sourceAsMap().get("doc_status"));
|
|
|
}
|
|
|
{
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "with_doc_as_upsert");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "with_doc_as_upsert");
|
|
|
updateRequest.doc(singletonMap("field", "initialized"));
|
|
|
updateRequest.fetchSource(true);
|
|
|
updateRequest.docAsUpsert(true);
|
|
@@ -619,7 +693,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
assertEquals("initialized", getResult.sourceAsMap().get("field"));
|
|
|
}
|
|
|
{
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "with_scripted_upsert");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "with_scripted_upsert");
|
|
|
updateRequest.fetchSource(true);
|
|
|
updateRequest.script(new Script(ScriptType.INLINE, "painless", "ctx._source.level = params.test", singletonMap("test", "C")));
|
|
|
updateRequest.scriptedUpsert(true);
|
|
@@ -637,7 +711,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
}
|
|
|
{
|
|
|
IllegalStateException exception = expectThrows(IllegalStateException.class, () -> {
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", "id");
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "id");
|
|
|
updateRequest.doc(new IndexRequest().source(Collections.singletonMap("field", "doc"), XContentType.JSON));
|
|
|
updateRequest.upsert(new IndexRequest().source(Collections.singletonMap("field", "upsert"), XContentType.YAML));
|
|
|
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
|
@@ -647,6 +721,22 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testUpdateWithTypes() throws IOException {
|
|
|
+ IndexRequest indexRequest = new IndexRequest("index", "type", "id");
|
|
|
+ indexRequest.source(singletonMap("field", "value"));
|
|
|
+ IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
|
|
+
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", "type", "id");
|
|
|
+ updateRequest.doc(singletonMap("field", "updated"), randomFrom(XContentType.values()));
|
|
|
+ UpdateResponse updateResponse = execute(updateRequest,
|
|
|
+ highLevelClient()::update,
|
|
|
+ highLevelClient()::updateAsync,
|
|
|
+ expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
|
|
|
+
|
|
|
+ assertEquals(RestStatus.OK, updateResponse.status());
|
|
|
+ assertEquals(indexResponse.getVersion() + 1, updateResponse.getVersion());
|
|
|
+ }
|
|
|
+
|
|
|
public void testBulk() throws IOException {
|
|
|
int nbItems = randomIntBetween(10, 100);
|
|
|
boolean[] errors = new boolean[nbItems];
|
|
@@ -687,7 +777,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
bulkRequest.add(createRequest);
|
|
|
|
|
|
} else if (opType == DocWriteRequest.OpType.UPDATE) {
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", id)
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", id)
|
|
|
.doc(new IndexRequest().source(source, xContentType));
|
|
|
if (erroneous == false) {
|
|
|
assertEquals(RestStatus.CREATED,
|
|
@@ -996,7 +1086,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|
|
processor.add(createRequest);
|
|
|
|
|
|
} else if (opType == DocWriteRequest.OpType.UPDATE) {
|
|
|
- UpdateRequest updateRequest = new UpdateRequest("index", "_doc", id)
|
|
|
+ UpdateRequest updateRequest = new UpdateRequest("index", id)
|
|
|
.doc(new IndexRequest().source(xContentType, "id", i));
|
|
|
if (erroneous == false) {
|
|
|
assertEquals(RestStatus.CREATED,
|