diff --git a/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java b/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java index e30cd4130f7..bc4c60db2b9 100644 --- a/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java @@ -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; -} \ No newline at end of file +}