use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class BulkRequestTests method testBulkAddIterable.
public void testBulkAddIterable() {
BulkRequest bulkRequest = Requests.bulkRequest();
List<DocWriteRequest> requests = new ArrayList<>();
requests.add(new IndexRequest("test", "test", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value"));
requests.add(new UpdateRequest("test", "test", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value"));
requests.add(new DeleteRequest("test", "test", "id"));
bulkRequest.add(requests);
assertThat(bulkRequest.requests().size(), equalTo(3));
assertThat(bulkRequest.requests().get(0), instanceOf(IndexRequest.class));
assertThat(bulkRequest.requests().get(1), instanceOf(UpdateRequest.class));
assertThat(bulkRequest.requests().get(2), instanceOf(DeleteRequest.class));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class BulkWithUpdatesIT method testThatFailedUpdateRequestReturnsCorrectType.
// issue 6630
public void testThatFailedUpdateRequestReturnsCorrectType() throws Exception {
BulkResponse indexBulkItemResponse = client().prepareBulk().add(new IndexRequest("test", "type", "3").source("{ \"title\" : \"Great Title of doc 3\" }", XContentType.JSON)).add(new IndexRequest("test", "type", "4").source("{ \"title\" : \"Great Title of doc 4\" }", XContentType.JSON)).add(new IndexRequest("test", "type", "5").source("{ \"title\" : \"Great Title of doc 5\" }", XContentType.JSON)).add(new IndexRequest("test", "type", "6").source("{ \"title\" : \"Great Title of doc 6\" }", XContentType.JSON)).setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
assertNoFailures(indexBulkItemResponse);
BulkResponse bulkItemResponse = client().prepareBulk().add(new IndexRequest("test", "type", "1").source("{ \"title\" : \"Great Title of doc 1\" }", XContentType.JSON)).add(new IndexRequest("test", "type", "2").source("{ \"title\" : \"Great Title of doc 2\" }", XContentType.JSON)).add(new UpdateRequest("test", "type", "3").doc("{ \"date\" : \"2014-01-30T23:59:57\"}", XContentType.JSON)).add(new UpdateRequest("test", "type", "4").doc("{ \"date\" : \"2014-13-30T23:59:57\"}", XContentType.JSON)).add(new DeleteRequest("test", "type", "5")).add(new DeleteRequest("test", "type", "6")).get();
assertNoFailures(indexBulkItemResponse);
assertThat(bulkItemResponse.getItems().length, is(6));
assertThat(bulkItemResponse.getItems()[0].getOpType(), is(OpType.INDEX));
assertThat(bulkItemResponse.getItems()[1].getOpType(), is(OpType.INDEX));
assertThat(bulkItemResponse.getItems()[2].getOpType(), is(OpType.UPDATE));
assertThat(bulkItemResponse.getItems()[3].getOpType(), is(OpType.UPDATE));
assertThat(bulkItemResponse.getItems()[4].getOpType(), is(OpType.DELETE));
assertThat(bulkItemResponse.getItems()[5].getOpType(), is(OpType.DELETE));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class BulkWithUpdatesIT method testThatMissingIndexDoesNotAbortFullBulkRequest.
// issue 6410
public void testThatMissingIndexDoesNotAbortFullBulkRequest() throws Exception {
createIndex("bulkindex1", "bulkindex2");
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1")).add(new IndexRequest("bulkindex2", "index2_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")).add(new IndexRequest("bulkindex2", "index2_type").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2")).add(new UpdateRequest("bulkindex2", "index2_type", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar")).add(new DeleteRequest("bulkindex2", "index2_type", "3")).setRefreshPolicy(RefreshPolicy.IMMEDIATE);
client().bulk(bulkRequest).get();
SearchResponse searchResponse = client().prepareSearch("bulkindex*").get();
assertHitCount(searchResponse, 3);
assertAcked(client().admin().indices().prepareClose("bulkindex2"));
BulkResponse bulkResponse = client().bulk(bulkRequest).get();
assertThat(bulkResponse.hasFailures(), is(true));
assertThat(bulkResponse.getItems().length, is(5));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class AbstractAsyncBulkByScrollActionScriptTestCase method testChangeSource.
public void testChangeSource() {
IndexRequest index = applyScript((Map<String, Object> ctx) -> {
@SuppressWarnings("unchecked") Map<String, Object> source = (Map<String, Object>) ctx.get("_source");
source.put("bar", "cat");
});
assertEquals("cat", index.sourceAsMap().get("bar"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project elasticsearch by elastic.
the class AbstractAsyncBulkByScrollActionScriptTestCase method applyScript.
@SuppressWarnings("unchecked")
protected <T extends ActionRequest> T applyScript(Consumer<Map<String, Object>> scriptBody) {
IndexRequest index = new IndexRequest("index", "type", "1").source(singletonMap("foo", "bar"));
ScrollableHitSource.Hit doc = new ScrollableHitSource.BasicHit("test", "type", "id", 0);
ExecutableScript executableScript = new SimpleExecutableScript(scriptBody);
when(scriptService.executable(any(CompiledScript.class), Matchers.<Map<String, Object>>any())).thenReturn(executableScript);
AbstractAsyncBulkByScrollAction<Request> action = action(scriptService, request().setScript(EMPTY_SCRIPT));
RequestWrapper<?> result = action.buildScriptApplier().apply(AbstractAsyncBulkByScrollAction.wrap(index), doc);
return (result != null) ? (T) result.self() : null;
}
Aggregations