|
14 | 14 | import org.elasticsearch.action.OriginalIndices; |
15 | 15 | import org.elasticsearch.common.Strings; |
16 | 16 | import org.elasticsearch.common.bytes.BytesReference; |
| 17 | +import org.elasticsearch.common.collect.Iterators; |
17 | 18 | import org.elasticsearch.common.io.stream.DelayableWriteable; |
18 | 19 | import org.elasticsearch.common.io.stream.StreamInput; |
19 | 20 | import org.elasticsearch.common.io.stream.StreamOutput; |
20 | 21 | import org.elasticsearch.common.io.stream.Writeable; |
21 | 22 | import org.elasticsearch.common.lucene.Lucene; |
22 | 23 | import org.elasticsearch.common.util.concurrent.ConcurrentCollections; |
23 | | -import org.elasticsearch.common.xcontent.ChunkedToXContent; |
| 24 | +import org.elasticsearch.common.xcontent.ChunkedToXContentHelper; |
24 | 25 | import org.elasticsearch.common.xcontent.ChunkedToXContentObject; |
25 | 26 | import org.elasticsearch.core.Nullable; |
26 | 27 | import org.elasticsearch.core.RefCounted; |
@@ -391,17 +392,24 @@ public Clusters getClusters() { |
391 | 392 | @Override |
392 | 393 | public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) { |
393 | 394 | assert hasReferences(); |
394 | | - return ChunkedToXContent.builder(params).xContentObject(innerToXContentChunked(params)); |
| 395 | + return getToXContentIterator(true, params); |
395 | 396 | } |
396 | 397 |
|
397 | 398 | public Iterator<? extends ToXContent> innerToXContentChunked(ToXContent.Params params) { |
398 | | - return ChunkedToXContent.builder(params) |
399 | | - .append(SearchResponse.this::headerToXContent) |
400 | | - .append(clusters) |
401 | | - .append(hits) |
402 | | - .appendIfPresent(aggregations) |
403 | | - .appendIfPresent(suggest) |
404 | | - .appendIfPresent(profileResults); |
| 399 | + return getToXContentIterator(false, params); |
| 400 | + } |
| 401 | + |
| 402 | + private Iterator<ToXContent> getToXContentIterator(boolean wrapInObject, ToXContent.Params params) { |
| 403 | + return Iterators.concat( |
| 404 | + wrapInObject ? ChunkedToXContentHelper.startObject() : Collections.emptyIterator(), |
| 405 | + ChunkedToXContentHelper.singleChunk(SearchResponse.this::headerToXContent), |
| 406 | + Iterators.single(clusters), |
| 407 | + hits.toXContentChunked(params), |
| 408 | + aggregations == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(aggregations), |
| 409 | + suggest == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(suggest), |
| 410 | + profileResults == null ? Collections.emptyIterator() : ChunkedToXContentHelper.singleChunk(profileResults), |
| 411 | + wrapInObject ? ChunkedToXContentHelper.endObject() : Collections.emptyIterator() |
| 412 | + ); |
405 | 413 | } |
406 | 414 |
|
407 | 415 | public XContentBuilder headerToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { |
|
0 commit comments