use of org.elasticsearch.action.bulk.BulkRequestBuilder in project elasticsearch by elastic.
the class RetryTests method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
createIndex("source");
// Build the test data. Don't use indexRandom because that won't work consistently with such small thread pools.
BulkRequestBuilder bulk = client().prepareBulk();
for (int i = 0; i < DOC_COUNT; i++) {
bulk.add(client().prepareIndex("source", "test").setSource("foo", "bar " + i));
}
Retry retry = Retry.on(EsRejectedExecutionException.class).policy(BackoffPolicy.exponentialBackoff());
BulkResponse response = retry.withSyncBackoff(client(), bulk.request());
assertFalse(response.buildFailureMessage(), response.hasFailures());
client().admin().indices().prepareRefresh("source").get();
}
use of org.elasticsearch.action.bulk.BulkRequestBuilder in project elasticsearch by elastic.
the class ShardInfoIT method testBulkWithIndexAndDeleteItems.
public void testBulkWithIndexAndDeleteItems() throws Exception {
prepareIndex(1);
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
for (int i = 0; i < 10; i++) {
bulkRequestBuilder.add(client().prepareIndex("idx", "type").setSource("{}", XContentType.JSON));
}
BulkResponse bulkResponse = bulkRequestBuilder.get();
bulkRequestBuilder = client().prepareBulk();
for (BulkItemResponse item : bulkResponse) {
assertThat(item.isFailed(), equalTo(false));
assertShardInfo(item.getResponse());
bulkRequestBuilder.add(client().prepareDelete("idx", "type", item.getId()));
}
bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse item : bulkResponse) {
assertThat(item.isFailed(), equalTo(false));
assertShardInfo(item.getResponse());
}
}
use of org.elasticsearch.action.bulk.BulkRequestBuilder in project elasticsearch by elastic.
the class ShardInfoIT method testBulkWithUpdateItems.
public void testBulkWithUpdateItems() throws Exception {
prepareIndex(1);
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
for (int i = 0; i < 10; i++) {
bulkRequestBuilder.add(client().prepareUpdate("idx", "type", Integer.toString(i)).setDoc("{}", XContentType.JSON).setDocAsUpsert(true));
}
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse item : bulkResponse) {
assertThat(item.isFailed(), equalTo(false));
assertShardInfo(item.getResponse());
}
}
use of org.elasticsearch.action.bulk.BulkRequestBuilder in project elasticsearch-river-kafka by endgameinc.
the class RawMessageHandlerTest method testIt.
public void testIt() throws Exception {
byte[] data = "somedata".getBytes();
List<String> l = new ArrayList<>();
MessageHandler m = new RawMessageHandler();
Message message = createMock(Message.class);
expect(message.payload()).andReturn(ByteBuffer.wrap(data));
BulkRequestBuilder bulkRequestBuilder = createMock(BulkRequestBuilder.class);
expect(bulkRequestBuilder.add(aryEq(data), eq(0), eq(data.length), eq(false))).andReturn(null);
replay(message, bulkRequestBuilder);
m.handle(bulkRequestBuilder, message);
verify(bulkRequestBuilder, message);
}
use of org.elasticsearch.action.bulk.BulkRequestBuilder in project elasticsearch by elastic.
the class SearchCancellationIT method indexTestData.
private void indexTestData() {
for (int i = 0; i < 5; i++) {
// Make sure we have a few segments
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
for (int j = 0; j < 20; j++) {
bulkRequestBuilder.add(client().prepareIndex("test", "type", Integer.toString(i * 5 + j)).setSource("field", "value"));
}
assertNoFailures(bulkRequestBuilder.get());
}
}
Aggregations