Add a toString() method to MultiSearchResponse

This commit is contained in:
David Pilato 2012-10-06 09:49:46 +02:00 committed by Shay Banon
parent 840eaf983d
commit b2597b5316
1 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.common.xcontent.XContentFactory;
import java.io.IOException;
import java.util.Iterator;
@ -168,4 +169,17 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult
static final XContentBuilderString RESPONSES = new XContentBuilderString("responses");
static final XContentBuilderString ERROR = new XContentBuilderString("error");
}
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
toXContent(builder, EMPTY_PARAMS);
builder.endObject();
return builder.string();
} catch (IOException e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
}