Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query DSL: deprecate BytesFilterBuilder in favour of WrapperFilterBuilder #11112

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
/**
* FilterBuilder that constructs filters from {@link org.elasticsearch.common.bytes.BytesReference}
* source
*
* @deprecated replace with {@link WrapperFilterBuilder}
*/
@Deprecated
public class BytesFilterBuilder extends BaseFilterBuilder {

private final BytesReference source;

public BytesFilterBuilder(BytesReference source) {
this.source = source;

}

@Override
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/elasticsearch/index/query/FilterBuilders.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,19 +553,34 @@ public static IndicesFilterBuilder indicesFilter(FilterBuilder filter, String...
return new IndicesFilterBuilder(filter, indices);
}

/**
* A Filter builder which allows building a query thanks to a JSON string or binary data.
*/
public static WrapperFilterBuilder wrapperFilter(String filter) {
return new WrapperFilterBuilder(filter);
}

/**
* A Filter builder which allows building a query thanks to a JSON string or binary data.
*/
public static WrapperFilterBuilder wrapperFilter(byte[] data, int offset, int length) {
return new WrapperFilterBuilder(data, offset, length);
}

/**
* A Filter builder which allows building a query thanks to a JSON string or binary data.
*/
public static WrapperFilterBuilder wrapperFilter(BytesReference source) {
return new WrapperFilterBuilder(source);
}

/**
* Constructs a bytes filter to generate a filter from a {@link BytesReference} source
* @deprecated replace with {@link #wrapperFilter(byte[], int, int)}
*
* @param source The filter source
*/
@Deprecated
public static BytesFilterBuilder bytesFilter(BytesReference source) {
return new BytesFilterBuilder(source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@
*/

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
* A Filter builder which allows building a query given JSON string or binary data provided as input. 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
* query builders.
*/
Expand All @@ -41,18 +36,33 @@ public class WrapperFilterBuilder extends BaseFilterBuilder {
private final int offset;
private final int length;

/**
* Creates a filter builder given a query 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 query 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 query 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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)))
.setSearchType(SearchType.COUNT)
.setTerminateAfter(1);
} else {
Expand Down