Skip to content

Commit b2597b5

Browse files
dadoonetkimchy
authored andcommitted
Add a toString() method to MultiSearchResponse
1 parent 840eaf9 commit b2597b5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/elasticsearch/action/search/MultiSearchResponse.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.common.xcontent.ToXContent;
1010
import org.elasticsearch.common.xcontent.XContentBuilder;
1111
import org.elasticsearch.common.xcontent.XContentBuilderString;
12+
import org.elasticsearch.common.xcontent.XContentFactory;
1213

1314
import java.io.IOException;
1415
import java.util.Iterator;
@@ -168,4 +169,17 @@ static final class Fields {
168169
static final XContentBuilderString RESPONSES = new XContentBuilderString("responses");
169170
static final XContentBuilderString ERROR = new XContentBuilderString("error");
170171
}
172+
173+
@Override
174+
public String toString() {
175+
try {
176+
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
177+
builder.startObject();
178+
toXContent(builder, EMPTY_PARAMS);
179+
builder.endObject();
180+
return builder.string();
181+
} catch (IOException e) {
182+
return "{ \"error\" : \"" + e.getMessage() + "\"}";
183+
}
184+
}
171185
}

0 commit comments

Comments
 (0)