Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.DelayableWriteable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.RefCounted;
Expand Down Expand Up @@ -391,17 +392,24 @@ public Clusters getClusters() {
@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
assert hasReferences();
return ChunkedToXContent.builder(params).xContentObject(innerToXContentChunked(params));
return getToXContentIterator(true, params);
}

public Iterator<? extends ToXContent> innerToXContentChunked(ToXContent.Params params) {
return ChunkedToXContent.builder(params)
.append(SearchResponse.this::headerToXContent)
.append(clusters)
.append(hits)
.appendIfPresent(aggregations)
.appendIfPresent(suggest)
.appendIfPresent(profileResults);
return getToXContentIterator(false, params);
}

private Iterator<ToXContent> getToXContentIterator(boolean wrapInObject, ToXContent.Params params) {
return Iterators.concat(
wrapInObject ? ChunkedToXContentHelper.startObject() : Collections.emptyIterator(),
ChunkedToXContentHelper.singleChunk(SearchResponse.this::headerToXContent),
Iterators.single(clusters),
hits.toXContentChunked(params),
aggregations == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(aggregations),
suggest == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(suggest),
profileResults == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(profileResults),
wrapInObject ? ChunkedToXContentHelper.endObject() : Collections.emptyIterator()
);
}

public XContentBuilder headerToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
Expand Down