diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java index 4428133cc35..fdea84c4d43 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java @@ -31,6 +31,17 @@ import java.io.IOException; */ public abstract class BaseQueryBuilder implements QueryBuilder { + @Override public String toString() { + try { + XContentBuilder builder = XContentFactory.safeJsonBuilder(); + builder.prettyPrint(); + toXContent(builder, EMPTY_PARAMS); + return builder.string(); + } catch (Exception e) { + throw new QueryBuilderException("Failed to build query", e); + } + } + @Override public BytesStream buildAsUnsafeBytes() throws QueryBuilderException { return buildAsUnsafeBytes(XContentType.JSON); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index 6b616ec815e..23373ad9335 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -90,5 +90,6 @@ public class BoostingQueryBuilder extends BaseQueryBuilder { if (boost != -1) { builder.field("boost", boost); } + builder.endObject(); } } \ No newline at end of file