Skip to content

Commit

Permalink
Merge branch 'making-BulkRequest-implement-RefCounted' into making-Bu…
Browse files Browse the repository at this point in the history
…lkShardRequest-implement-RefCounted
  • Loading branch information
masseyke committed Dec 8, 2023
2 parents ab6dc42 + 1ed8296 commit 2e5c7c8
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,32 @@ private void putComposableIndexTemplate(final String id, final List<String> patt
}

private void indexDocs(final String dataStream, int numDocs, long startTime) {
final BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < numDocs; i++) {
final String timestamp = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(startTime + i);
bulkRequest.add(
new IndexRequest(dataStream).opType(DocWriteRequest.OpType.CREATE)
.source(
String.format(
Locale.ROOT,
"{\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\"}",
DEFAULT_TIMESTAMP_FIELD,
timestamp,
"routing_field",
0,
"counter",
i + 1
),
XContentType.JSON
)
);
try (BulkRequest bulkRequest = new BulkRequest()) {
for (int i = 0; i < numDocs; i++) {
final String timestamp = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(startTime + i);
bulkRequest.add(
new IndexRequest(dataStream).opType(DocWriteRequest.OpType.CREATE)
.source(
String.format(
Locale.ROOT,
"{\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\"}",
DEFAULT_TIMESTAMP_FIELD,
timestamp,
"routing_field",
0,
"counter",
i + 1
),
XContentType.JSON
)
);
}
final BulkResponse bulkResponse = client().bulk(bulkRequest).actionGet();
final BulkItemResponse[] items = bulkResponse.getItems();
assertThat(items.length, equalTo(numDocs));
assertThat(bulkResponse.hasFailures(), equalTo(false));
final RefreshResponse refreshResponse = indicesAdmin().refresh(new RefreshRequest(dataStream)).actionGet();
assertThat(refreshResponse.getStatus().getStatus(), equalTo(RestStatus.OK.getStatus()));
}
final BulkResponse bulkResponse = client().bulk(bulkRequest).actionGet();
final BulkItemResponse[] items = bulkResponse.getItems();
assertThat(items.length, equalTo(numDocs));
assertThat(bulkResponse.hasFailures(), equalTo(false));
final RefreshResponse refreshResponse = indicesAdmin().refresh(new RefreshRequest(dataStream)).actionGet();
assertThat(refreshResponse.getStatus().getStatus(), equalTo(RestStatus.OK.getStatus()));
}
}

0 comments on commit 2e5c7c8

Please sign in to comment.