Add toString() for FilterBuilders

Closes #2887.
This commit is contained in:
David Pilato 2013-04-12 19:58:30 +02:00
parent bf21466291
commit 3b7a195f6f
1 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import java.io.IOException;
@ -28,6 +29,18 @@ import java.io.IOException;
*/
public abstract class BaseFilterBuilder implements FilterBuilder {
@Override
public String toString() {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.prettyPrint();
toXContent(builder, EMPTY_PARAMS);
return builder.string();
} catch (Exception e) {
throw new QueryBuilderException("Failed to build filter", e);
}
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
@ -37,4 +50,4 @@ public abstract class BaseFilterBuilder implements FilterBuilder {
}
protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException;
}
}