diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index 292bb633a2975..bb426aa8c83aa 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -116,6 +116,10 @@ Some query builders have been removed or renamed: * `filtered(...)` removed. Use `filteredQuery(...)` instead. * `inQuery(...)` removed. +`BytesFilterBuilder` and the corresponding `FilterBuilders#bytesFilter` method have been +removed in favour of the existing `WrapperFilterBuilder`, which has now an additional +constructor that accepts a `BytesReference` as argument. + === Aggregations The `date_histogram` aggregation now returns a `Histogram` object in the response, and the `DateHistogram` class has been removed. Similarly diff --git a/src/main/java/org/elasticsearch/index/query/BytesFilterBuilder.java b/src/main/java/org/elasticsearch/index/query/BytesFilterBuilder.java deleted file mode 100644 index a86ea239f70ca..0000000000000 --- a/src/main/java/org/elasticsearch/index/query/BytesFilterBuilder.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elasticsearch 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.common.bytes.BytesReference; -import org.elasticsearch.common.xcontent.*; - -import java.io.IOException; - -/** - * FilterBuilder that constructs filters from {@link org.elasticsearch.common.bytes.BytesReference} - * source - */ -public class BytesFilterBuilder extends BaseFilterBuilder { - - private final BytesReference source; - - public BytesFilterBuilder(BytesReference source) { - this.source = source; - - } - - @Override - protected void doXContent(XContentBuilder builder, Params params) throws IOException { - try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) { - // unwrap the first layer of json dictionary - parser.nextToken(); - parser.nextToken(); - builder.copyCurrentStructure(parser); - } - } -} diff --git a/src/main/java/org/elasticsearch/index/query/FilterBuilders.java b/src/main/java/org/elasticsearch/index/query/FilterBuilders.java index 3cd63fb6e51b9..cdb3322d54197 100644 --- a/src/main/java/org/elasticsearch/index/query/FilterBuilders.java +++ b/src/main/java/org/elasticsearch/index/query/FilterBuilders.java @@ -29,7 +29,10 @@ /** * A static factory for simple "import static" usage. */ -public abstract class FilterBuilders { +public final class FilterBuilders { + + private FilterBuilders() { + } /** * A filter that matches all documents. @@ -548,24 +551,24 @@ public static IndicesFilterBuilder indicesFilter(FilterBuilder filter, String... return new IndicesFilterBuilder(filter, indices); } + /** + * Creates a {@link WrapperFilterBuilder} given a filter provided as a string + */ public static WrapperFilterBuilder wrapperFilter(String filter) { return new WrapperFilterBuilder(filter); } + /** + * Creates a {@link WrapperFilterBuilder} given a filter provided as a bytes array + */ public static WrapperFilterBuilder wrapperFilter(byte[] data, int offset, int length) { return new WrapperFilterBuilder(data, offset, length); } /** - * Constructs a bytes filter to generate a filter from a {@link BytesReference} source - * - * @param source The filter source + * Creates a {@link WrapperFilterBuilder} given a filter provided as a {@link BytesReference} */ - public static BytesFilterBuilder bytesFilter(BytesReference source) { - return new BytesFilterBuilder(source); - } - - private FilterBuilders() { - + public static WrapperFilterBuilder wrapperFilter(BytesReference source) { + return new WrapperFilterBuilder(source); } } diff --git a/src/main/java/org/elasticsearch/index/query/WrapperFilterBuilder.java b/src/main/java/org/elasticsearch/index/query/WrapperFilterBuilder.java index 8a63c0a4a1624..8dfb77b538b0e 100644 --- a/src/main/java/org/elasticsearch/index/query/WrapperFilterBuilder.java +++ b/src/main/java/org/elasticsearch/index/query/WrapperFilterBuilder.java @@ -18,21 +18,16 @@ */ package org.elasticsearch.index.query; -/** - * Created by IntelliJ IDEA. - * User: cedric - * Date: 12/07/11 - * Time: 11:30 - */ import com.google.common.base.Charsets; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; /** - * A Filter builder which allows building a filter thanks to a JSON string or binary data. This is useful when you want - * to use the Java Builder API but still have JSON filter strings at hand that you want to combine with other + * A Filter builder which allows building a filter given JSON string or binary data provided as input. This is useful + * when you want to use the Java API but still have JSON filter strings at hand that you want to combine with other * query builders. */ public class WrapperFilterBuilder extends BaseFilterBuilder { @@ -41,18 +36,33 @@ public class WrapperFilterBuilder extends BaseFilterBuilder { private final int offset; private final int length; + /** + * Creates a filter builder given a filter provided as a string + */ public WrapperFilterBuilder(String source) { this.source = source.getBytes(Charsets.UTF_8); this.offset = 0; this.length = this.source.length; } + /** + * Creates a filter builder given a byte provided as a bytes array + */ public WrapperFilterBuilder(byte[] source, int offset, int length) { this.source = source; this.offset = offset; this.length = length; } + /** + * Creates a filter builder given a filter provided as a {@link BytesReference} + */ + public WrapperFilterBuilder(BytesReference source) { + this.source = source.array(); + this.offset = source.arrayOffset(); + this.length = source.length(); + } + @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(WrapperFilterParser.NAME); diff --git a/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggester.java b/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggester.java index 96fd23a56f15c..54ff95e0c84f1 100644 --- a/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggester.java +++ b/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggester.java @@ -28,7 +28,10 @@ import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.CharsRefBuilder; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.search.*; +import org.elasticsearch.action.search.MultiSearchRequestBuilder; +import org.elasticsearch.action.search.MultiSearchResponse; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; @@ -42,7 +45,9 @@ import org.elasticsearch.search.suggest.Suggest.Suggestion; import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry.Option; -import org.elasticsearch.search.suggest.*; +import org.elasticsearch.search.suggest.SuggestContextParser; +import org.elasticsearch.search.suggest.SuggestUtils; +import org.elasticsearch.search.suggest.Suggester; import org.elasticsearch.search.suggest.phrase.NoisyChannelSpellChecker.Result; import java.io.IOException; @@ -168,7 +173,7 @@ private MultiSearchResponse fetchMatchingDocCountResponses(Correction[] correcti if (isFilter) { req = client.prepareSearch() .setPreference(suggestions.getPreference()) - .setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.bytesFilter(querySource))) + .setQuery(QueryBuilders.constantScoreQuery(FilterBuilders.wrapperFilter(querySource))) .setSize(0) .setTerminateAfter(1); } else {