Skip to content

Commit

Permalink
Make some chunked xcontent more efficient (elastic#115512)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop authored and jfreden committed Nov 4, 2024
1 parent 89ea4f1 commit 8dc56e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params).object(ob -> {
ob.field(ERRORS, hasFailures());
ob.field(TOOK, tookInMillis);
return ChunkedToXContent.builder(params).object(ob -> ob.append((b, p) -> {
b.field(ERRORS, hasFailures());
b.field(TOOK, tookInMillis);
if (ingestTookInMillis != BulkResponse.NO_INGEST_TOOK) {
ob.field(INGEST_TOOK, ingestTookInMillis);
b.field(INGEST_TOOK, ingestTookInMillis);
}
ob.array(ITEMS, Iterators.forArray(responses));
});
return b;
}).array(ITEMS, Iterators.forArray(responses)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,15 @@ private void endObject() {
* Creates an object, with the specified {@code contents}
*/
public ChunkedToXContentBuilder xContentObject(ToXContent contents) {
startObject();
append(contents);
endObject();
addChunk((b, p) -> contents.toXContent(b.startObject(), p).endObject());
return this;
}

/**
* Creates an object named {@code name}, with the specified {@code contents}
*/
public ChunkedToXContentBuilder xContentObject(String name, ToXContent contents) {
startObject(name);
append(contents);
endObject();
addChunk((b, p) -> contents.toXContent(b.startObject(name), p).endObject());
return this;
}

Expand Down

0 comments on commit 8dc56e1

Please sign in to comment.