diff --git a/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java b/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java index bc4c60db2b9..bd32834b835 100644 --- a/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BaseFilterBuilder.java @@ -19,8 +19,11 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; @@ -37,7 +40,23 @@ public abstract class BaseFilterBuilder implements FilterBuilder { toXContent(builder, EMPTY_PARAMS); return builder.string(); } catch (Exception e) { - throw new QueryBuilderException("Failed to build filter", e); + throw new ElasticSearchException("Failed to build filter", e); + } + } + + @Override + public BytesReference buildAsBytes() throws ElasticSearchException { + return buildAsBytes(XContentType.JSON); + } + + @Override + public BytesReference buildAsBytes(XContentType contentType) throws ElasticSearchException { + try { + XContentBuilder builder = XContentFactory.contentBuilder(contentType); + toXContent(builder, EMPTY_PARAMS); + return builder.bytes(); + } catch (Exception e) { + throw new ElasticSearchException("Failed to build filter", e); } } diff --git a/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java index 675f6e8679e..c97d7707ecf 100644 --- a/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BaseQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -39,23 +40,23 @@ public abstract class BaseQueryBuilder implements QueryBuilder { toXContent(builder, EMPTY_PARAMS); return builder.string(); } catch (Exception e) { - throw new QueryBuilderException("Failed to build query", e); + throw new ElasticSearchException("Failed to build query", e); } } @Override - public BytesReference buildAsBytes() throws QueryBuilderException { + public BytesReference buildAsBytes() throws ElasticSearchException { return buildAsBytes(XContentType.JSON); } @Override - public BytesReference buildAsBytes(XContentType contentType) throws QueryBuilderException { + public BytesReference buildAsBytes(XContentType contentType) throws ElasticSearchException { try { XContentBuilder builder = XContentFactory.contentBuilder(contentType); toXContent(builder, EMPTY_PARAMS); return builder.bytes(); } catch (Exception e) { - throw new QueryBuilderException("Failed to build query", e); + throw new ElasticSearchException("Failed to build query", e); } } diff --git a/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index 1942a55df16..f4e28c96fc9 100644 --- a/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -72,13 +73,13 @@ public class BoostingQueryBuilder extends BaseQueryBuilder implements BoostableQ @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { if (positiveQuery == null) { - throw new QueryBuilderException("boosting query requires positive query to be set"); + throw new ElasticSearchIllegalArgumentException("boosting query requires positive query to be set"); } if (negativeQuery == null) { - throw new QueryBuilderException("boosting query requires negative query to be set"); + throw new ElasticSearchIllegalArgumentException("boosting query requires negative query to be set"); } if (negativeBoost == -1) { - throw new QueryBuilderException("boosting query requires negativeBoost to be set"); + throw new ElasticSearchIllegalArgumentException("boosting query requires negativeBoost to be set"); } builder.startObject(BoostingQueryParser.NAME); builder.field("positive"); @@ -93,4 +94,4 @@ public class BoostingQueryBuilder extends BaseQueryBuilder implements BoostableQ } builder.endObject(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/FilterBuilder.java b/src/main/java/org/elasticsearch/index/query/FilterBuilder.java index fcdcf20b0c4..31cec73c295 100644 --- a/src/main/java/org/elasticsearch/index/query/FilterBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FilterBuilder.java @@ -19,11 +19,18 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentType; /** * */ public interface FilterBuilder extends ToXContent { -} \ No newline at end of file + BytesReference buildAsBytes() throws ElasticSearchException; + + BytesReference buildAsBytes(XContentType contentType) throws ElasticSearchException; + +} diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisFieldQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisFieldQueryBuilder.java index 3e95f1aaf40..6fd7c1193bc 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisFieldQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisFieldQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -112,7 +113,7 @@ public class FuzzyLikeThisFieldQueryBuilder extends BaseQueryBuilder implements builder.startObject(FuzzyLikeThisFieldQueryParser.NAME); builder.startObject(name); if (likeText == null) { - throw new QueryBuilderException("fuzzyLikeThis requires 'likeText' to be provided"); + throw new ElasticSearchIllegalArgumentException("fuzzyLikeThis requires 'likeText' to be provided"); } builder.field("like_text", likeText); if (maxQueryTerms != null) { @@ -142,4 +143,4 @@ public class FuzzyLikeThisFieldQueryBuilder extends BaseQueryBuilder implements builder.endObject(); builder.endObject(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryBuilder.java index b9d39f3589f..9a6b8a62bd2 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -125,7 +126,7 @@ public class FuzzyLikeThisQueryBuilder extends BaseQueryBuilder implements Boost builder.endArray(); } if (likeText == null) { - throw new QueryBuilderException("fuzzyLikeThis requires 'likeText' to be provided"); + throw new ElasticSearchIllegalArgumentException("fuzzyLikeThis requires 'likeText' to be provided"); } builder.field("like_text", likeText); if (maxQueryTerms != null) { @@ -154,4 +155,4 @@ public class FuzzyLikeThisQueryBuilder extends BaseQueryBuilder implements Boost } builder.endObject(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxFilterBuilder.java b/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxFilterBuilder.java index 05249b558ac..e3a82d93cf3 100644 --- a/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxFilterBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxFilterBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.geo.GeoHashUtils; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -136,7 +137,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder { } else if (topLeft != null) { builder.startArray("top_left").value(topLeft.lon()).value(topLeft.lat()).endArray(); } else { - throw new QueryBuilderException("geo_bounding_box requires 'top_left' to be set"); + throw new ElasticSearchIllegalArgumentException("geo_bounding_box requires 'top_left' to be set"); } if (bottomRightGeohash != null) { @@ -144,7 +145,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder { } else if (bottomRight != null) { builder.startArray("bottom_right").value(bottomRight.lon()).value(bottomRight.lat()).endArray(); } else { - throw new QueryBuilderException("geo_bounding_box requires 'bottom_right' to be set"); + throw new ElasticSearchIllegalArgumentException("geo_bounding_box requires 'bottom_right' to be set"); } builder.endObject(); diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisFieldQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisFieldQueryBuilder.java index ff318b40b91..1ffa9ec1f72 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisFieldQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisFieldQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -178,7 +179,7 @@ public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements B builder.startObject(MoreLikeThisFieldQueryParser.NAME); builder.startObject(name); if (likeText == null) { - throw new QueryBuilderException("moreLikeThisField requires 'like_text' to be provided"); + throw new ElasticSearchIllegalArgumentException("moreLikeThisField requires 'like_text' to be provided"); } builder.field("like_text", likeText); if (percentTermsToMatch != -1) { @@ -227,4 +228,4 @@ public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements B builder.endObject(); builder.endObject(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index a08411fa277..e6c707d4e65 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -192,7 +193,7 @@ public class MoreLikeThisQueryBuilder extends BaseQueryBuilder implements Boosta builder.endArray(); } if (likeText == null) { - throw new QueryBuilderException("moreLikeThis requires 'likeText' to be provided"); + throw new ElasticSearchIllegalArgumentException("moreLikeThis requires 'likeText' to be provided"); } builder.field("like_text", likeText); if (percentTermsToMatch != -1) { @@ -240,4 +241,4 @@ public class MoreLikeThisQueryBuilder extends BaseQueryBuilder implements Boosta } builder.endObject(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/index/query/QueryBuilder.java b/src/main/java/org/elasticsearch/index/query/QueryBuilder.java index f443f842e51..bb0a01c0758 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/QueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentType; @@ -28,7 +29,7 @@ import org.elasticsearch.common.xcontent.XContentType; */ public interface QueryBuilder extends ToXContent { - BytesReference buildAsBytes() throws QueryBuilderException; + BytesReference buildAsBytes() throws ElasticSearchException; - BytesReference buildAsBytes(XContentType contentType) throws QueryBuilderException; + BytesReference buildAsBytes(XContentType contentType) throws ElasticSearchException; } diff --git a/src/main/java/org/elasticsearch/index/query/QueryBuilderException.java b/src/main/java/org/elasticsearch/index/query/QueryBuilderException.java deleted file mode 100644 index 8b450716555..00000000000 --- a/src/main/java/org/elasticsearch/index/query/QueryBuilderException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.query; - -import org.elasticsearch.ElasticSearchException; - -/** - * - */ -public class QueryBuilderException extends ElasticSearchException { - - public QueryBuilderException(String msg) { - super(msg); - } - - public QueryBuilderException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java index 36410b9a099..f97cbf492d6 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -77,10 +78,10 @@ public class SpanNearQueryBuilder extends BaseQueryBuilder implements SpanQueryB @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { if (clauses.isEmpty()) { - throw new QueryBuilderException("Must have at least one clause when building a spanNear query"); + throw new ElasticSearchIllegalArgumentException("Must have at least one clause when building a spanNear query"); } if (slop == null) { - throw new QueryBuilderException("Must set the slop when building a spanNear query"); + throw new ElasticSearchIllegalArgumentException("Must set the slop when building a spanNear query"); } builder.startObject(SpanNearQueryParser.NAME); builder.startArray("clauses"); diff --git a/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java index 0c340296284..5cf138527e5 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanNotQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -62,10 +63,10 @@ public class SpanNotQueryBuilder extends BaseQueryBuilder implements SpanQueryBu @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { if (include == null) { - throw new QueryBuilderException("Must specify include when using spanNot query"); + throw new ElasticSearchIllegalArgumentException("Must specify include when using spanNot query"); } if (exclude == null) { - throw new QueryBuilderException("Must specify exclude when using spanNot query"); + throw new ElasticSearchIllegalArgumentException("Must specify exclude when using spanNot query"); } builder.startObject(SpanNotQueryParser.NAME); builder.field("include"); diff --git a/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java b/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java index cb30e2d07af..3b4a70627fe 100644 --- a/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/SpanOrQueryBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -56,7 +57,7 @@ public class SpanOrQueryBuilder extends BaseQueryBuilder implements SpanQueryBui @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { if (clauses.isEmpty()) { - throw new QueryBuilderException("Must have at least one clause when building a spanOr query"); + throw new ElasticSearchIllegalArgumentException("Must have at least one clause when building a spanOr query"); } builder.startObject(SpanOrQueryParser.NAME); builder.startArray("clauses"); @@ -72,4 +73,4 @@ public class SpanOrQueryBuilder extends BaseQueryBuilder implements SpanQueryBui } builder.endObject(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java b/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java index e9d4d994491..ca333334151 100644 --- a/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java +++ b/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java @@ -26,17 +26,16 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilderException; public class RescoreBuilder implements ToXContent { private Rescorer rescorer; private Integer windowSize; - + public static QueryRescorer queryRescorer(QueryBuilder queryBuilder) { return new QueryRescorer(queryBuilder); } - + public RescoreBuilder rescorer(Rescorer rescorer) { this.rescorer = rescorer; return this; @@ -61,7 +60,7 @@ public class RescoreBuilder implements ToXContent { } public static abstract class Rescorer implements ToXContent { - + private String name; public Rescorer(String name) { @@ -76,16 +75,16 @@ public class RescoreBuilder implements ToXContent { } protected abstract XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException; - + } - + public static class QueryRescorer extends Rescorer { private static final String NAME = "query"; private QueryBuilder queryBuilder; private Float rescoreQueryWeight; private Float queryWeight; private String scoreMode; - + /** * Creates a new {@link QueryRescorer} instance * @param builder the query builder to build the rescore query from @@ -101,7 +100,7 @@ public class RescoreBuilder implements ToXContent { this.queryWeight = queryWeight; return this; } - + /** * Sets the original query weight for rescoring. The default is 1.0 */