Skip to content

Commit f1690e4

Browse files
committed
Make PercolateResponse a ToXContentObject
1 parent 3e5ee05 commit f1690e4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

modules/percolator/src/main/java/org/elasticsearch/percolator/MultiPercolateResponse.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.elasticsearch.common.io.stream.StreamInput;
2525
import org.elasticsearch.common.io.stream.StreamOutput;
2626
import org.elasticsearch.common.io.stream.Streamable;
27-
import org.elasticsearch.common.xcontent.ToXContent;
27+
import org.elasticsearch.common.xcontent.ToXContentObject;
2828
import org.elasticsearch.common.xcontent.XContentBuilder;
2929

3030
import java.io.IOException;
@@ -40,7 +40,7 @@
4040
* @deprecated Instead use multi search API with {@link PercolateQueryBuilder}
4141
*/
4242
@Deprecated
43-
public class MultiPercolateResponse extends ActionResponse implements Iterable<MultiPercolateResponse.Item>, ToXContent {
43+
public class MultiPercolateResponse extends ActionResponse implements Iterable<MultiPercolateResponse.Item>, ToXContentObject {
4444

4545
private Item[] items;
4646

@@ -73,17 +73,19 @@ public Item[] getItems() {
7373

7474
@Override
7575
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
76+
builder.startObject();
7677
builder.startArray(Fields.RESPONSES);
7778
for (MultiPercolateResponse.Item item : items) {
78-
builder.startObject();
7979
if (item.isFailure()) {
80+
builder.startObject();
8081
ElasticsearchException.renderException(builder, params, item.getFailure());
82+
builder.endObject();
8183
} else {
8284
item.getResponse().toXContent(builder, params);
8385
}
84-
builder.endObject();
8586
}
8687
builder.endArray();
88+
builder.endObject();
8789
return builder;
8890
}
8991

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateResponse.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.elasticsearch.common.io.stream.Streamable;
2727
import org.elasticsearch.common.text.Text;
2828
import org.elasticsearch.common.unit.TimeValue;
29-
import org.elasticsearch.common.xcontent.ToXContent;
29+
import org.elasticsearch.common.xcontent.ToXContentObject;
3030
import org.elasticsearch.common.xcontent.XContentBuilder;
3131
import org.elasticsearch.rest.action.RestActions;
3232
import org.elasticsearch.search.aggregations.InternalAggregations;
@@ -45,7 +45,7 @@
4545
* @deprecated Instead use search API with {@link PercolateQueryBuilder}
4646
*/
4747
@Deprecated
48-
public class PercolateResponse extends BroadcastResponse implements Iterable<PercolateResponse.Match>, ToXContent {
48+
public class PercolateResponse extends BroadcastResponse implements Iterable<PercolateResponse.Match>, ToXContentObject {
4949

5050
public static final Match[] EMPTY = new Match[0];
5151
// PercolateQuery emits this score if no 'query' is defined in the percolate request
@@ -113,6 +113,13 @@ public Iterator<Match> iterator() {
113113

114114
@Override
115115
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
116+
builder.startObject();
117+
innerToXContent(builder, params);
118+
builder.endObject();
119+
return builder;
120+
}
121+
122+
public XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException {
116123
builder.field(Fields.TOOK, tookInMillis);
117124
RestActions.buildBroadcastShardsHeader(builder, params, this);
118125

0 commit comments

Comments
 (0)