add toString to SearchRequestBuilder

This commit is contained in:
kimchy 2011-05-14 14:52:36 +03:00
parent 10108d9a4e
commit cb691ef54b
2 changed files with 14 additions and 0 deletions

View File

@ -574,6 +574,10 @@ public class SearchRequestBuilder extends BaseRequestBuilder<SearchRequest, Sear
return sourceBuilder();
}
@Override public String toString() {
return internalBuilder().toString();
}
@Override protected void doExecute(ActionListener<SearchResponse> listener) {
request.source(sourceBuilder());
client.search(request, listener);

View File

@ -380,6 +380,16 @@ public class SearchSourceBuilder implements ToXContent {
return this;
}
@Override public String toString() {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
toXContent(builder, ToXContent.EMPTY_PARAMS);
return builder.string();
} catch (Exception e) {
return "{ \"error\" : \"" + e.getMessage() + "\"}";
}
}
public FastByteArrayOutputStream buildAsUnsafeBytes(XContentType contentType) throws SearchSourceBuilderException {
try {
XContentBuilder builder = XContentFactory.contentBuilder(contentType);