cleanup codebase to work with SearchSourceBuilder
This commit is contained in:
parent
9116c1c19f
commit
e1759b1a60
|
@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.Template;
|
||||
import org.elasticsearch.search.Scroll;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
|
@ -42,6 +41,7 @@ import org.elasticsearch.search.sort.SortBuilder;
|
|||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -122,14 +122,6 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* An optional timeout to control how long search is allowed to take.
|
||||
*/
|
||||
public SearchRequestBuilder setTimeout(String timeout) {
|
||||
sourceBuilder().timeout(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* An optional document count, upon collecting which the search
|
||||
* query will early terminate
|
||||
|
@ -180,118 +172,16 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
|
|||
*
|
||||
* @see org.elasticsearch.index.query.QueryBuilders
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(QueryBuilder queryBuilder) {
|
||||
public SearchRequestBuilder setQuery(QueryBuilder<?> queryBuilder) {
|
||||
sourceBuilder().query(queryBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search source builder with a raw search query.
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(String query) {
|
||||
sourceBuilder().query(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search source builder with a raw search query.
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(BytesReference queryBinary) {
|
||||
sourceBuilder().query(queryBinary);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search source builder with a raw search query.
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(byte[] queryBinary) {
|
||||
sourceBuilder().query(queryBinary);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search source builder with a raw search query.
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(byte[] queryBinary, int queryBinaryOffset, int queryBinaryLength) {
|
||||
sourceBuilder().query(queryBinary, queryBinaryOffset, queryBinaryLength);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search source builder with a raw search query.
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(XContentBuilder query) {
|
||||
sourceBuilder().query(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search source builder with a raw search query.
|
||||
*/
|
||||
public SearchRequestBuilder setQuery(Map query) {
|
||||
sourceBuilder().query(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter that will be executed after the query has been executed and only has affect on the search hits
|
||||
* (not aggregations). This filter is always executed as last filtering mechanism.
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(QueryBuilder postFilter) {
|
||||
sourceBuilder().postFilter(postFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the query executed that only applies to the search query
|
||||
* (and not aggs for example).
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(String postFilter) {
|
||||
sourceBuilder().postFilter(postFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the query executed that only applies to the search query
|
||||
* (and not aggs for example).
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(BytesReference postFilter) {
|
||||
sourceBuilder().postFilter(postFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the query executed that only applies to the search query
|
||||
* (and not aggs for example).
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(byte[] postFilter) {
|
||||
sourceBuilder().postFilter(postFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the query executed that only applies to the search query
|
||||
* (and not aggs for example).
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(byte[] postFilter, int postFilterOffset, int postFilterLength) {
|
||||
sourceBuilder().postFilter(postFilter, postFilterOffset, postFilterLength);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the query executed that only applies to the search query
|
||||
* (and not aggs for example).
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(XContentBuilder postFilter) {
|
||||
sourceBuilder().postFilter(postFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a filter on the query executed that only applies to the search query
|
||||
* (and not aggs for example).
|
||||
*/
|
||||
public SearchRequestBuilder setPostFilter(Map postFilter) {
|
||||
public SearchRequestBuilder setPostFilter(QueryBuilder<?> postFilter) {
|
||||
sourceBuilder().postFilter(postFilter);
|
||||
return this;
|
||||
}
|
||||
|
@ -465,7 +355,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
|
|||
* the source of the document will be returned.
|
||||
*/
|
||||
public SearchRequestBuilder addFields(String... fields) {
|
||||
sourceBuilder().fields(fields);
|
||||
sourceBuilder().fields(Arrays.asList(fields));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -477,30 +367,6 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw (xcontent) binary representation of addAggregation to use.
|
||||
*/
|
||||
public SearchRequestBuilder setAggregations(BytesReference aggregations) {
|
||||
sourceBuilder().aggregations(aggregations);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw (xcontent) binary representation of addAggregation to use.
|
||||
*/
|
||||
public SearchRequestBuilder setAggregations(byte[] aggregations) {
|
||||
sourceBuilder().aggregations(aggregations);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw (xcontent) binary representation of addAggregation to use.
|
||||
*/
|
||||
public SearchRequestBuilder setAggregations(byte[] aggregations, int aggregationsOffset, int aggregationsLength) {
|
||||
sourceBuilder().aggregations(aggregations, aggregationsOffset, aggregationsLength);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw (xcontent) binary representation of addAggregation to use.
|
||||
*/
|
||||
|
@ -509,14 +375,6 @@ public class SearchRequestBuilder extends ActionRequestBuilder<SearchRequest, Se
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a raw (xcontent) binary representation of addAggregation to use.
|
||||
*/
|
||||
public SearchRequestBuilder setAggregations(Map aggregations) {
|
||||
sourceBuilder().aggregations(aggregations);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a field to be highlighted with default fragment size of 100 characters, and
|
||||
* default number of fragments of 5.
|
||||
|
|
|
@ -29,7 +29,13 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
||||
|
@ -61,9 +67,11 @@ public class RestValidateQueryAction extends BaseRestHandler {
|
|||
if (RestActions.hasBodyContent(request)) {
|
||||
validateQueryRequest.source(RestActions.getRestContent(request));
|
||||
} else {
|
||||
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
|
||||
if (querySourceBuilder != null) {
|
||||
validateQueryRequest.source(querySourceBuilder);
|
||||
QueryBuilder<?> queryBuilder = RestActions.parseQuerySource(request);
|
||||
if (queryBuilder != null) {
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder();
|
||||
querySourceBuilder.setQuery(queryBuilder);
|
||||
validateQueryRequest.source(querySourceBuilder.buildAsBytes());
|
||||
}
|
||||
}
|
||||
validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||
|
|
|
@ -27,7 +27,11 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.Table;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestResponseListener;
|
||||
import org.elasticsearch.rest.action.support.RestTable;
|
||||
|
@ -61,9 +65,11 @@ public class RestCountAction extends AbstractCatAction {
|
|||
if (source != null) {
|
||||
countRequest.source(source);
|
||||
} else {
|
||||
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
|
||||
if (querySourceBuilder != null) {
|
||||
countRequest.source(querySourceBuilder);
|
||||
QueryBuilder<?> queryBuilder = RestActions.parseQuerySource(request);
|
||||
if (queryBuilder != null) {
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder();
|
||||
querySourceBuilder.setQuery(queryBuilder);
|
||||
countRequest.source(querySourceBuilder.buildAsBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,15 +28,21 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
||||
import static org.elasticsearch.action.count.CountRequest.DEFAULT_MIN_SCORE;
|
||||
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.action.support.RestActions.buildBroadcastShardsHeader;
|
||||
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -61,9 +67,11 @@ public class RestCountAction extends BaseRestHandler {
|
|||
if (RestActions.hasBodyContent(request)) {
|
||||
countRequest.source(RestActions.getRestContent(request));
|
||||
} else {
|
||||
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
|
||||
if (querySourceBuilder != null) {
|
||||
countRequest.source(querySourceBuilder);
|
||||
QueryBuilder<?> queryBuilder = RestActions.parseQuerySource(request);
|
||||
if (queryBuilder != null) {
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder();
|
||||
querySourceBuilder.setQuery(queryBuilder);
|
||||
countRequest.source(querySourceBuilder.buildAsBytes());
|
||||
}
|
||||
}
|
||||
countRequest.routing(request.param("routing"));
|
||||
|
|
|
@ -27,7 +27,14 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
|
||||
|
@ -51,9 +58,11 @@ public class RestExistsAction extends BaseRestHandler {
|
|||
if (RestActions.hasBodyContent(request)) {
|
||||
existsRequest.source(RestActions.getRestContent(request));
|
||||
} else {
|
||||
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
|
||||
if (querySourceBuilder != null) {
|
||||
existsRequest.source(querySourceBuilder);
|
||||
QueryBuilder<?> queryBuilder = RestActions.parseQuerySource(request);
|
||||
if (queryBuilder != null) {
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder();
|
||||
querySourceBuilder.setQuery(queryBuilder);
|
||||
existsRequest.source(querySourceBuilder.buildAsBytes());
|
||||
}
|
||||
}
|
||||
existsRequest.routing(request.param("routing"));
|
||||
|
|
|
@ -23,12 +23,12 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
|
@ -41,6 +41,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|||
import org.elasticsearch.search.fetch.source.FetchSourceContext;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
|
||||
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
|
@ -128,10 +129,10 @@ public class RestSearchAction extends BaseRestHandler {
|
|||
public static SearchSourceBuilder parseSearchSource(RestRequest request) {
|
||||
SearchSourceBuilder searchSourceBuilder = null;
|
||||
|
||||
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
|
||||
if (querySourceBuilder != null) {
|
||||
QueryBuilder<?> queryBuilder = RestActions.parseQuerySource(request);
|
||||
if (queryBuilder != null) {
|
||||
searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(querySourceBuilder);
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
}
|
||||
|
||||
int from = request.paramAsInt("from", -1);
|
||||
|
@ -263,9 +264,9 @@ public class RestSearchAction extends BaseRestHandler {
|
|||
searchSourceBuilder = new SearchSourceBuilder();
|
||||
}
|
||||
String suggestMode = request.param("suggest_mode");
|
||||
searchSourceBuilder.suggest().addSuggestion(
|
||||
searchSourceBuilder.suggest(new SuggestBuilder().addSuggestion(
|
||||
termSuggestion(suggestField).field(suggestField).text(suggestText).size(suggestSize)
|
||||
.suggestMode(suggestMode)
|
||||
.suggestMode(suggestMode))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,13 +21,17 @@ package org.elasticsearch.rest.action.support;
|
|||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.Operator;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.QueryStringQueryBuilder;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
|
@ -85,7 +89,7 @@ public class RestActions {
|
|||
builder.endObject();
|
||||
}
|
||||
|
||||
public static QuerySourceBuilder parseQuerySource(RestRequest request) {
|
||||
public static QueryBuilder<?> parseQuerySource(RestRequest request) {
|
||||
String queryString = request.param("q");
|
||||
if (queryString == null) {
|
||||
return null;
|
||||
|
@ -100,7 +104,7 @@ public class RestActions {
|
|||
if (defaultOperator != null) {
|
||||
queryBuilder.defaultOperator(Operator.fromString(defaultOperator));
|
||||
}
|
||||
return new QuerySourceBuilder().setQuery(queryBuilder);
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.junit.Test;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class SearchRequestBuilderTests extends ESTestCase {
|
||||
|
@ -72,26 +71,6 @@ public class SearchRequestBuilderTests extends ESTestCase {
|
|||
assertThat(searchRequestBuilder.toString(), equalTo(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXContentBuilderQueryToString() throws IOException {
|
||||
SearchRequestBuilder searchRequestBuilder = client.prepareSearch();
|
||||
XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
|
||||
xContentBuilder.startObject();
|
||||
xContentBuilder.startObject("match_all");
|
||||
xContentBuilder.endObject();
|
||||
xContentBuilder.endObject();
|
||||
searchRequestBuilder.setQuery(xContentBuilder);
|
||||
assertThat(searchRequestBuilder.toString(), equalTo(new SearchSourceBuilder().query(xContentBuilder).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringQueryToString() {
|
||||
SearchRequestBuilder searchRequestBuilder = client.prepareSearch();
|
||||
String query = "{ \"match_all\" : {} }";
|
||||
searchRequestBuilder.setQuery(query);
|
||||
assertThat(searchRequestBuilder.toString(), containsString("\"query\":{ \"match_all\" : {} }"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringSourceToString() {
|
||||
SearchRequestBuilder searchRequestBuilder = client.prepareSearch();
|
||||
|
|
|
@ -144,28 +144,32 @@ public class TemplateQueryIT extends ESIntegTestCase {
|
|||
assertHitCount(sr, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawEscapedTemplate() throws IOException {
|
||||
String query = "{\"template\": {\"query\": \"{\\\"match_{{template}}\\\": {}}\\\"\",\"params\" : {\"template\" : \"all\"}}}";
|
||||
|
||||
SearchResponse sr = client().prepareSearch().setQuery(query).get();
|
||||
assertHitCount(sr, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawTemplate() throws IOException {
|
||||
String query = "{\"template\": {\"query\": {\"match_{{template}}\": {}},\"params\" : {\"template\" : \"all\"}}}";
|
||||
SearchResponse sr = client().prepareSearch().setQuery(query).get();
|
||||
assertHitCount(sr, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawFSTemplate() throws IOException {
|
||||
String query = "{\"template\": {\"file\": \"storedTemplate\",\"params\" : {\"template\" : \"all\"}}}";
|
||||
|
||||
SearchResponse sr = client().prepareSearch().setQuery(query).get();
|
||||
assertHitCount(sr, 2);
|
||||
}
|
||||
// NORELEASE These need to be tested in TemplateQueryBuilderTests
|
||||
// @Test
|
||||
// public void testRawEscapedTemplate() throws IOException {
|
||||
// String query =
|
||||
// "{\"template\": {\"query\": \"{\\\"match_{{template}}\\\": {}}\\\"\",\"params\" : {\"template\" : \"all\"}}}";
|
||||
//
|
||||
// SearchResponse sr = client().prepareSearch().setQuery(query).get();
|
||||
// assertHitCount(sr, 2);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRawTemplate() throws IOException {
|
||||
// String query =
|
||||
// "{\"template\": {\"query\": {\"match_{{template}}\": {}},\"params\" : {\"template\" : \"all\"}}}";
|
||||
// SearchResponse sr = client().prepareSearch().setQuery(query).get();
|
||||
// assertHitCount(sr, 2);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRawFSTemplate() throws IOException {
|
||||
// String query =
|
||||
// "{\"template\": {\"file\": \"storedTemplate\",\"params\" : {\"template\" : \"all\"}}}";
|
||||
//
|
||||
// SearchResponse sr = client().prepareSearch().setQuery(query).get();
|
||||
// assertHitCount(sr, 2);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testSearchRequestTemplateSource() throws Exception {
|
||||
|
@ -451,12 +455,15 @@ public class TemplateQueryIT extends ESIntegTestCase {
|
|||
.execute().actionGet();
|
||||
assertHitCount(sr, 1);
|
||||
|
||||
String query = "{\"template\": {\"id\": \"3\",\"params\" : {\"fieldParam\" : \"foo\"}}}";
|
||||
sr = client().prepareSearch().setQuery(query).get();
|
||||
// "{\"template\": {\"id\": \"3\",\"params\" : {\"fieldParam\" : \"foo\"}}}";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("fieldParam", "foo");
|
||||
TemplateQueryBuilder templateQuery = new TemplateQueryBuilder(new Template("3", ScriptType.INDEXED, null, null, params));
|
||||
sr = client().prepareSearch().setQuery(templateQuery).get();
|
||||
assertHitCount(sr, 4);
|
||||
|
||||
query = "{\"template\": {\"id\": \"/mustache/3\",\"params\" : {\"fieldParam\" : \"foo\"}}}";
|
||||
sr = client().prepareSearch().setQuery(query).get();
|
||||
templateQuery = new TemplateQueryBuilder(new Template("/mustache/3", ScriptType.INDEXED, null, null, params));
|
||||
sr = client().prepareSearch().setQuery(templateQuery).get();
|
||||
assertHitCount(sr, 4);
|
||||
}
|
||||
|
||||
|
@ -471,7 +478,7 @@ public class TemplateQueryIT extends ESIntegTestCase {
|
|||
|
||||
int iterations = randomIntBetween(2, 11);
|
||||
for (int i = 1; i < iterations; i++) {
|
||||
PutIndexedScriptResponse scriptResponse = client().preparePutIndexedScript(MustacheScriptEngineService.NAME, "git01",
|
||||
PutIndexedScriptResponse scriptResponse = client().preparePutIndexedScript(MustacheScriptEngineService.NAME, "git01",
|
||||
"{\"query\": {\"match\": {\"searchtext\": {\"query\": \"{{P_Keyword1}}\",\"type\": \"ooophrase_prefix\"}}}}").get();
|
||||
assertEquals(i * 2 - 1, scriptResponse.getVersion());
|
||||
|
||||
|
@ -507,7 +514,7 @@ public class TemplateQueryIT extends ESIntegTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testIndexedTemplateWithArray() throws Exception {
|
||||
createIndex(ScriptService.SCRIPT_INDEX);
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
|
|||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -41,17 +42,30 @@ import org.junit.Test;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.elasticsearch.client.Requests.indexRequest;
|
||||
import static org.elasticsearch.client.Requests.searchRequest;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.exponentialDecayFunction;
|
||||
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.gaussDecayFunction;
|
||||
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.linearDecayFunction;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertOrderedSearchHits;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.closeTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.isOneOf;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
|
||||
public class DecayFunctionScoreIT extends ESIntegTestCase {
|
||||
|
@ -432,10 +446,10 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
SearchResponse sr = response.actionGet();
|
||||
assertOrderedSearchHits(sr, "2", "1");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParseDateMath() throws Exception {
|
||||
|
||||
|
||||
assertAcked(prepareCreate("test").addMapping(
|
||||
"type1",
|
||||
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "string")
|
||||
|
@ -456,7 +470,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
|
||||
assertNoFailures(sr);
|
||||
assertOrderedSearchHits(sr, "1", "2");
|
||||
|
||||
|
||||
sr = client().search(
|
||||
searchRequest().source(
|
||||
searchSource().query(
|
||||
|
@ -582,9 +596,9 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
double lat = 100 + (int) (10.0 * (float) (i) / (float) (numDocs));
|
||||
double lat = 100 + (int) (10.0 * (i) / (numDocs));
|
||||
double lon = 100;
|
||||
int day = (int) (29.0 * (float) (i) / (float) (numDocs)) + 1;
|
||||
int day = (int) (29.0 * (i) / (numDocs)) + 1;
|
||||
String dayString = day < 10 ? "0" + Integer.toString(day) : Integer.toString(day);
|
||||
String date = "2013-05-" + dayString;
|
||||
|
||||
|
@ -774,7 +788,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
|
||||
assertThat(sh.getAt(0).getId(), equalTo("2"));
|
||||
assertThat(sh.getAt(1).getId(), equalTo("1"));
|
||||
assertThat((double)(1.0 - sh.getAt(0).getScore()), closeTo((double)((1.0 - sh.getAt(1).getScore())/3.0), 1.e-6d));
|
||||
assertThat(1.0 - sh.getAt(0).getScore(), closeTo((1.0 - sh.getAt(1).getScore())/3.0, 1.e-6d));
|
||||
response = client().search(
|
||||
searchRequest().source(
|
||||
searchSource().query(
|
||||
|
@ -782,7 +796,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
sr = response.actionGet();
|
||||
assertSearchHits(sr, "1", "2");
|
||||
sh = sr.getHits();
|
||||
assertThat((double) (sh.getAt(0).getScore()), closeTo((double) (sh.getAt(1).getScore()), 1.e-6d));
|
||||
assertThat((double) (sh.getAt(0).getScore()), closeTo((sh.getAt(1).getScore()), 1.e-6d));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -799,11 +813,9 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
|
||||
XContentBuilder query = XContentFactory.jsonBuilder();
|
||||
// query that contains a single function and a functions[] array
|
||||
query.startObject().startObject("function_score").field("weight", "1").startArray("functions").startObject().startObject("script_score").field("script", "3").endObject().endObject().endArray().endObject().endObject();
|
||||
query.startObject().startObject("query").startObject("function_score").field("weight", "1").startArray("functions").startObject().startObject("script_score").field("script", "3").endObject().endObject().endArray().endObject().endObject().endObject();
|
||||
try {
|
||||
client().search(
|
||||
searchRequest().source(
|
||||
searchSource().query(query))).actionGet();
|
||||
client().search(searchRequest().source(query.bytes())).actionGet();
|
||||
fail("Search should result in SearchPhaseExecutionException");
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
logger.info(e.shardFailures()[0].reason());
|
||||
|
@ -812,11 +824,9 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
|
||||
query = XContentFactory.jsonBuilder();
|
||||
// query that contains a single function (but not boost factor) and a functions[] array
|
||||
query.startObject().startObject("function_score").startObject("random_score").field("seed", 3).endObject().startArray("functions").startObject().startObject("random_score").field("seed", 3).endObject().endObject().endArray().endObject().endObject();
|
||||
query.startObject().startObject("query").startObject("function_score").startObject("random_score").field("seed", 3).endObject().startArray("functions").startObject().startObject("random_score").field("seed", 3).endObject().endObject().endArray().endObject().endObject().endObject();
|
||||
try {
|
||||
client().search(
|
||||
searchRequest().source(
|
||||
searchSource().query(query))).actionGet();
|
||||
client().search(searchRequest().source(query.bytes())).actionGet();
|
||||
fail("Search should result in SearchPhaseExecutionException");
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
logger.info(e.shardFailures()[0].reason());
|
||||
|
@ -836,18 +846,20 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
"}\n";
|
||||
|
||||
String query = "{\n" +
|
||||
" \"function_score\": {\n" +
|
||||
" \"score_mode\": \"sum\",\n" +
|
||||
" \"boost_mode\": \"replace\",\n" +
|
||||
" \"functions\": [\n" +
|
||||
" {\n" +
|
||||
" \"filter\": {\n" +
|
||||
" \"term\": {\n" +
|
||||
" \"text\": \"baseball\"\n" +
|
||||
" \"query\": {\n" +
|
||||
" \"function_score\": {\n" +
|
||||
" \"score_mode\": \"sum\",\n" +
|
||||
" \"boost_mode\": \"replace\",\n" +
|
||||
" \"functions\": [\n" +
|
||||
" {\n" +
|
||||
" \"filter\": {\n" +
|
||||
" \"term\": {\n" +
|
||||
" \"text\": \"baseball\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}\n";
|
||||
|
||||
|
@ -855,9 +867,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
ensureYellow("t");
|
||||
try {
|
||||
client().search(
|
||||
searchRequest().source(
|
||||
searchSource().query(query))).actionGet();
|
||||
client().search(searchRequest().source(new BytesArray(query))).actionGet();
|
||||
fail("Should fail with SearchPhaseExecutionException");
|
||||
} catch (SearchPhaseExecutionException failure) {
|
||||
assertThat(failure.toString(), containsString("SearchParseException"));
|
||||
|
@ -865,33 +875,34 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
query = "{\n" +
|
||||
" \"function_score\": {\n" +
|
||||
" \"score_mode\": \"sum\",\n" +
|
||||
" \"boost_mode\": \"replace\",\n" +
|
||||
" \"functions\": [\n" +
|
||||
" {\n" +
|
||||
" \"filter\": {\n" +
|
||||
" \"term\": {\n" +
|
||||
" \"text\": \"baseball\"\n" +
|
||||
" }\n" +
|
||||
" \"query\": {\n" +
|
||||
" \"function_score\": {\n" +
|
||||
" \"score_mode\": \"sum\",\n" +
|
||||
" \"boost_mode\": \"replace\",\n" +
|
||||
" \"functions\": [\n" +
|
||||
" {\n" +
|
||||
" \"filter\": {\n" +
|
||||
" \"term\": {\n" +
|
||||
" \"text\": \"baseball\"\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"weight\": 2\n" +
|
||||
" },\n" +
|
||||
" \"weight\": 2\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"filter\": {\n" +
|
||||
" \"term\": {\n" +
|
||||
" \"text\": \"baseball\"\n" +
|
||||
" {\n" +
|
||||
" \"filter\": {\n" +
|
||||
" \"term\": {\n" +
|
||||
" \"text\": \"baseball\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
try {
|
||||
client().search(
|
||||
searchRequest().source(
|
||||
searchSource().query(query))).actionGet();
|
||||
searchRequest().source(new BytesArray(query))).actionGet();
|
||||
fail("Should fail with SearchPhaseExecutionException");
|
||||
} catch (SearchPhaseExecutionException failure) {
|
||||
assertThat(failure.toString(), containsString("SearchParseException"));
|
||||
|
|
|
@ -536,22 +536,22 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Testing lat/lon format");
|
||||
String pointTest1 = "{\"geohash_cell\": {\"pin\": {\"lat\": " + point.lat() + ",\"lon\": " + point.lon() + "},\"precision\": " + precision + ",\"neighbors\": true}}";
|
||||
SearchResponse results3 = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(pointTest1).execute().actionGet();
|
||||
assertHitCount(results3, neighbors.size() + 1);
|
||||
|
||||
|
||||
logger.info("Testing String format");
|
||||
String pointTest2 = "{\"geohash_cell\": {\"pin\": \"" + point.lat() + "," + point.lon() + "\",\"precision\": " + precision + ",\"neighbors\": true}}";
|
||||
SearchResponse results4 = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(pointTest2).execute().actionGet();
|
||||
assertHitCount(results4, neighbors.size() + 1);
|
||||
|
||||
logger.info("Testing Array format");
|
||||
String pointTest3 = "{\"geohash_cell\": {\"pin\": [" + point.lon() + "," + point.lat() + "],\"precision\": " + precision + ",\"neighbors\": true}}";
|
||||
SearchResponse results5 = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(pointTest3).execute().actionGet();
|
||||
assertHitCount(results5, neighbors.size() + 1);
|
||||
// NORELEASE these should be tested in GeohashCellQueryBuilderTests
|
||||
// logger.info("Testing lat/lon format");
|
||||
// String pointTest1 = "{\"geohash_cell\": {\"pin\": {\"lat\": " + point.lat() + ",\"lon\": " + point.lon() + "},\"precision\": " + precision + ",\"neighbors\": true}}";
|
||||
// SearchResponse results3 = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(pointTest1).execute().actionGet();
|
||||
// assertHitCount(results3, neighbors.size() + 1);
|
||||
//
|
||||
//
|
||||
// logger.info("Testing String format");
|
||||
// String pointTest2 = "{\"geohash_cell\": {\"pin\": \"" + point.lat() + "," + point.lon() + "\",\"precision\": " + precision + ",\"neighbors\": true}}";
|
||||
// SearchResponse results4 = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(pointTest2).execute().actionGet();
|
||||
// assertHitCount(results4, neighbors.size() + 1);
|
||||
//
|
||||
// logger.info("Testing Array format");
|
||||
// String pointTest3 = "{\"geohash_cell\": {\"pin\": [" + point.lon() + "," + point.lat() + "],\"precision\": " + precision + ",\"neighbors\": true}}";
|
||||
// SearchResponse results5 = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(pointTest3).execute().actionGet();
|
||||
// assertHitCount(results5, neighbors.size() + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -225,43 +225,44 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
|
|||
assertThat(before, equalTo(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingMultipleShapes() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("type1")
|
||||
.startObject("properties")
|
||||
.startObject("location1")
|
||||
.field("type", "geo_shape")
|
||||
.endObject()
|
||||
.startObject("location2")
|
||||
.field("type", "geo_shape")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.string();
|
||||
|
||||
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||
ensureYellow();
|
||||
|
||||
String p1 = "\"location1\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}";
|
||||
String p2 = "\"location2\" : {\"type\":\"polygon\", \"coordinates\":[[[-20,-20],[20,-20],[20,20],[-20,20],[-20,-20]]]}";
|
||||
String o1 = "{" + p1 + ", " + p2 + "}";
|
||||
|
||||
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource(o1));
|
||||
|
||||
String filter = "{\"geo_shape\": {\"location2\": {\"indexed_shape\": {"
|
||||
+ "\"id\": \"1\","
|
||||
+ "\"type\": \"type1\","
|
||||
+ "\"index\": \"test\","
|
||||
+ "\"path\": \"location2\""
|
||||
+ "}}}}";
|
||||
|
||||
SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(filter).execute().actionGet();
|
||||
assertSearchResponse(result);
|
||||
assertHitCount(result, 1);
|
||||
}
|
||||
// NORELEASE these should be tested in GeoShapeQueryBuilderTests
|
||||
// @Test
|
||||
// public void testParsingMultipleShapes() throws Exception {
|
||||
// String mapping = XContentFactory.jsonBuilder()
|
||||
// .startObject()
|
||||
// .startObject("type1")
|
||||
// .startObject("properties")
|
||||
// .startObject("location1")
|
||||
// .field("type", "geo_shape")
|
||||
// .endObject()
|
||||
// .startObject("location2")
|
||||
// .field("type", "geo_shape")
|
||||
// .endObject()
|
||||
// .endObject()
|
||||
// .endObject()
|
||||
// .endObject()
|
||||
// .string();
|
||||
//
|
||||
// assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||
// ensureYellow();
|
||||
//
|
||||
// String p1 = "\"location1\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}";
|
||||
// String p2 = "\"location2\" : {\"type\":\"polygon\", \"coordinates\":[[[-20,-20],[20,-20],[20,20],[-20,20],[-20,-20]]]}";
|
||||
// String o1 = "{" + p1 + ", " + p2 + "}";
|
||||
//
|
||||
// indexRandom(true, client().prepareIndex("test", "type1", "1").setSource(o1));
|
||||
//
|
||||
// String filter = "{\"geo_shape\": {\"location2\": {\"indexed_shape\": {"
|
||||
// + "\"id\": \"1\","
|
||||
// + "\"type\": \"type1\","
|
||||
// + "\"index\": \"test\","
|
||||
// + "\"path\": \"location2\""
|
||||
// + "}}}}";
|
||||
//
|
||||
// SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(filter).execute().actionGet();
|
||||
// assertSearchResponse(result);
|
||||
// assertHitCount(result, 1);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testShapeFetchingPath() throws Exception {
|
||||
|
|
|
@ -602,7 +602,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1 and field2 produces different tags");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "test"))
|
||||
.highlight(highlight().order("score").preTags("<global>").postTags("</global>").fragmentSize(1).numOfFragments(1)
|
||||
.highlighter(highlight().order("score").preTags("<global>").postTags("</global>").fragmentSize(1).numOfFragments(1)
|
||||
.field(new HighlightBuilder.Field("field1").numOfFragments(2))
|
||||
.field(new HighlightBuilder.Field("field2").preTags("<field2>").postTags("</field2>").fragmentSize(50).requireFieldMatch(false)));
|
||||
|
||||
|
@ -632,7 +632,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
SearchSourceBuilder source = searchSource()
|
||||
//postings hl doesn't support require_field_match, its field needs to be queried directly
|
||||
.query(termQuery("field-postings", "test"))
|
||||
.highlight(highlight().field("field*").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field*").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -684,13 +684,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
containsString("source is forced for fields [field1] but type [type1] has disabled _source"));
|
||||
|
||||
SearchSourceBuilder searchSource = SearchSourceBuilder.searchSource().query(termQuery("field1", "quick"))
|
||||
.highlight(highlight().forceSource(true).field("field1"));
|
||||
.highlighter(highlight().forceSource(true).field("field1"));
|
||||
assertFailures(client().prepareSearch("test").setSource(searchSource),
|
||||
RestStatus.BAD_REQUEST,
|
||||
containsString("source is forced for fields [field1] but type [type1] has disabled _source"));
|
||||
|
||||
searchSource = SearchSourceBuilder.searchSource().query(termQuery("field1", "quick"))
|
||||
.highlight(highlight().forceSource(true).field("field*"));
|
||||
.highlighter(highlight().forceSource(true).field("field*"));
|
||||
assertFailures(client().prepareSearch("test").setSource(searchSource),
|
||||
RestStatus.BAD_REQUEST,
|
||||
matches("source is forced for fields \\[field\\d, field\\d\\] but type \\[type1\\] has disabled _source"));
|
||||
|
@ -708,7 +708,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "test"))
|
||||
.highlight(highlight().field("field1").order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().field("field1").order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -717,7 +717,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all, highlighting on field1");
|
||||
source = searchSource()
|
||||
.query(termQuery("_all", "test"))
|
||||
.highlight(highlight().field("field1").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field1").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -726,7 +726,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(termQuery("_all", "quick"))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -735,7 +735,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(prefixQuery("_all", "qui"))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -744,7 +744,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all with constant score, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(constantScoreQuery(prefixQuery("_all", "qui")))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -753,7 +753,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all with constant score, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(boolQuery().should(constantScoreQuery(prefixQuery("_all", "qui"))))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> brown fox jumps over the lazy dog"));
|
||||
|
@ -771,7 +771,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "test"))
|
||||
.highlight(highlight().field("field1", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().field("field1", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -780,7 +780,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all, highlighting on field1");
|
||||
source = searchSource()
|
||||
.query(termQuery("_all", "test"))
|
||||
.highlight(highlight().field("field1", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field1", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -790,7 +790,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(termQuery("_all", "quick"))
|
||||
.highlight(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -800,7 +800,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on _all, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(prefixQuery("_all", "qui"))
|
||||
.highlight(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -826,7 +826,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "t"))
|
||||
.highlight(highlight().highlighterType("fvh").field("field1", 20, 1).order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().highlighterType("fvh").field("field1", 20, 1).order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, containsString("<xxx>t</xxx>"));
|
||||
logger.info("--> done");
|
||||
|
@ -1371,7 +1371,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(boostingQuery(termQuery("field2", "brown"), termQuery("field2", "foobar")).negativeBoost(0.5f))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -1390,7 +1390,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(boostingQuery(termQuery("field2", "brown"), termQuery("field2", "foobar")).negativeBoost(0.5f))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -1410,7 +1410,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <x>quick</x> <x>brown</x> fox jumps over the lazy dog"));
|
||||
|
@ -1425,7 +1425,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
|
@ -1455,7 +1455,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field0");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(matchPhrasePrefixQuery("field0", "quick bro"))
|
||||
.highlight(highlight().field("field0").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field0").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -1464,7 +1464,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
source = searchSource()
|
||||
.query(matchPhrasePrefixQuery("field1", "quick bro"))
|
||||
.highlight(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -1481,7 +1481,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field3", "fast bro"))
|
||||
.highlight(highlight().field("field3").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field3").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -1489,7 +1489,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> highlighting and searching on field4");
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "the fast bro"))
|
||||
.highlight(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(equalTo("<x>The quick browse</x> button is a fancy thing, right bro?"), equalTo("<x>The quick brown</x> fox jumps over the lazy dog")));
|
||||
|
@ -1497,7 +1497,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> highlighting and searching on field4");
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca"))
|
||||
.highlight(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field4", 0, 1, equalTo("<x>a quick fast blue car</x>"));
|
||||
|
@ -1987,7 +1987,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "test"))
|
||||
.highlight(highlight().field("field1").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().field("field1").preTags("<xxx>").postTags("</xxx>"));
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("this is a <xxx>test</xxx>"));
|
||||
|
@ -1995,7 +1995,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on field1, highlighting on field1");
|
||||
source = searchSource()
|
||||
.query(termQuery("field1", "test"))
|
||||
.highlight(highlight().field("field1").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().field("field1").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -2004,7 +2004,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on field2, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(termQuery("field2", "quick"))
|
||||
.highlight(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().field("field2").order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -2013,7 +2013,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on field2, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(matchPhraseQuery("field2", "quick brown"))
|
||||
.highlight(highlight().field("field2").preTags("<xxx>").postTags("</xxx>"));
|
||||
.highlighter(highlight().field("field2").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -2024,7 +2024,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> searching on field2, highlighting on field2, falling back to the plain highlighter");
|
||||
source = searchSource()
|
||||
.query(matchPhraseQuery("_all", "quick brown"))
|
||||
.highlight(highlight().field("field2").preTags("<xxx>").postTags("</xxx>").highlighterType("highlighter").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2").preTags("<xxx>").postTags("</xxx>").highlighterType("highlighter").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -2059,7 +2059,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "fox"))
|
||||
.highlight(highlight()
|
||||
.highlighter(highlight()
|
||||
.field(new HighlightBuilder.Field("field1").numOfFragments(5).preTags("<field1>").postTags("</field1>")));
|
||||
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
@ -2074,7 +2074,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
source = searchSource()
|
||||
.query(termQuery("field1", "fox"))
|
||||
.highlight(highlight()
|
||||
.highlighter(highlight()
|
||||
.field(new HighlightBuilder.Field("field1").numOfFragments(0).preTags("<field1>").postTags("</field1>")));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
@ -2124,7 +2124,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(multiMatchQueryBuilder)
|
||||
.highlight(highlight().highlightQuery(randomBoolean() ? multiMatchQueryBuilder : null).highlighterType(highlighterType)
|
||||
.highlighter(highlight().highlightQuery(randomBoolean() ? multiMatchQueryBuilder : null).highlighterType(highlighterType)
|
||||
.field(new Field("field1").requireFieldMatch(true).preTags("<field1>").postTags("</field1>")));
|
||||
logger.info("Running multi-match type: [" + matchQueryType + "] highlight with type: [" + highlighterType + "]");
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
@ -2148,7 +2148,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("field1", "sentence"))
|
||||
.highlight(highlight().field("field1").order("score"));
|
||||
.highlighter(highlight().field("field1").order("score"));
|
||||
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
|
@ -2304,7 +2304,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(boostingQuery(termQuery("field2", "brown"), termQuery("field2", "foobar")).negativeBoost(0.5f))
|
||||
.highlight(highlight().field("field2").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field2").preTags("<x>").postTags("</x>"));
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick <x>brown</x> fox jumps over the lazy dog!"));
|
||||
|
@ -2319,7 +2319,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
|
||||
.highlight(highlight().field("field2").preTags("<x>").postTags("</x>"));
|
||||
.highlighter(highlight().field("field2").preTags("<x>").postTags("</x>"));
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
|
||||
|
@ -2345,7 +2345,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
logger.info("--> highlighting and searching on field2");
|
||||
|
||||
SearchSourceBuilder source = searchSource().query(prefixQuery("field2", "qui"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
|
||||
|
||||
|
@ -2360,7 +2360,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(fuzzyQuery("field2", "quck"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
|
||||
|
@ -2375,7 +2375,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(regexpQuery("field2", "qu[a-l]+k"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
|
||||
|
@ -2390,13 +2390,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(wildcardQuery("field2", "qui*"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
|
||||
|
||||
source = searchSource().query(wildcardQuery("field2", "qu*k"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
|
||||
|
@ -2412,7 +2412,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(rangeQuery("field2").gte("aaaa").lt("zzzz"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("<em>aaab</em>"));
|
||||
|
@ -2427,7 +2427,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(queryStringQuery("qui*").defaultField("field2"))
|
||||
.highlight(highlight().field("field2"));
|
||||
.highlighter(highlight().field("field2"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
|
||||
}
|
||||
|
@ -2443,7 +2443,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(constantScoreQuery(regexpQuery("field1", "pho[a-z]+")))
|
||||
.highlight(highlight().field("field1"));
|
||||
.highlighter(highlight().field("field1"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
|
||||
}
|
||||
|
@ -2462,7 +2462,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
.should(constantScoreQuery(QueryBuilders.missingQuery("field1")))
|
||||
.should(matchQuery("field1", "test"))
|
||||
.should(constantScoreQuery(queryStringQuery("field1:photo*"))))
|
||||
.highlight(highlight().field("field1"));
|
||||
.highlighter(highlight().field("field1"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
|
||||
}
|
||||
|
@ -2478,7 +2478,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(boolQuery().must(prefixQuery("field1", "photo")).should(matchQuery("field1", "test").minimumShouldMatch("0")))
|
||||
.highlight(highlight().field("field1"));
|
||||
.highlighter(highlight().field("field1"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
|
||||
}
|
||||
|
@ -2494,7 +2494,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(boolQuery().must(queryStringQuery("field1:photo*")).filter(missingQuery("field_null")))
|
||||
.highlight(highlight().field("field1"));
|
||||
.highlighter(highlight().field("field1"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
|
||||
}
|
||||
|
|
|
@ -145,15 +145,15 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
client().prepareSearch().setQuery(matchAllQuery()).setPostFilter(notQuery(termQuery("field1", "value3"))).get(),
|
||||
2l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passQueryAsStringTest() throws Exception {
|
||||
createIndex("test");
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1_1", "field2", "value2_1").setRefresh(true).get();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery("{ \"term\" : { \"field1\" : \"value1_1\" }}").get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
}
|
||||
// NORELEASE This should be tested in SearchSourceBuilderTests
|
||||
// @Test
|
||||
// public void passQueryAsStringTest() throws Exception {
|
||||
// createIndex("test");
|
||||
// client().prepareIndex("test", "type1", "1").setSource("field1", "value1_1", "field2", "value2_1").setRefresh(true).get();
|
||||
//
|
||||
// SearchResponse searchResponse = client().prepareSearch().setQuery("{ \"term\" : { \"field1\" : \"value1_1\" }}").get();
|
||||
// assertHitCount(searchResponse, 1l);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testIndexOptions() throws Exception {
|
||||
|
@ -310,9 +310,10 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery("{ \"common\" : { \"field1\" : { \"query\" : \"the lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 4 } } } }").get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
// NORELEASE This should be tested in SearchSourceBuilderTests
|
||||
// searchResponse = client().prepareSearch().setQuery("{ \"common\" : { \"field1\" : { \"query\" : \"the lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 4 } } } }").get();
|
||||
// assertHitCount(searchResponse, 1l);
|
||||
// assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
// Default
|
||||
searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1)).get();
|
||||
|
@ -402,9 +403,10 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery("{ \"common\" : { \"field1\" : { \"query\" : \"the fast lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 6 } } } }").get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertFirstHit(searchResponse, hasId("2"));
|
||||
// NORELEASE This should be tested in SearchSourceBuilderTests
|
||||
// searchResponse = client().prepareSearch().setQuery("{ \"common\" : { \"field1\" : { \"query\" : \"the fast lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 6 } } } }").get();
|
||||
// assertHitCount(searchResponse, 1l);
|
||||
// assertFirstHit(searchResponse, hasId("2"));
|
||||
|
||||
// Default
|
||||
searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the fast lazy fox brown").cutoffFrequency(1)).get();
|
||||
|
@ -1506,13 +1508,14 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertHitCount(searchResponse, 2l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyTopLevelFilter() {
|
||||
client().prepareIndex("test", "type", "1").setSource("field", "value").setRefresh(true).get();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch().setPostFilter("{}").get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
}
|
||||
// NORELEASE This should be tested in SearchSourceBuilderTests
|
||||
// @Test
|
||||
// public void testEmptyTopLevelFilter() {
|
||||
// client().prepareIndex("test", "type", "1").setSource("field", "value").setRefresh(true).get();
|
||||
//
|
||||
// SearchResponse searchResponse = client().prepareSearch().setPostFilter("{}").get();
|
||||
// assertHitCount(searchResponse, 1l);
|
||||
// }
|
||||
|
||||
@Test // see #2926
|
||||
public void testMustNot() throws IOException, ExecutionException, InterruptedException {
|
||||
|
@ -2235,25 +2238,26 @@ functionScoreQuery(scriptFunction(new Script("_doc['score'].value")))).setMinSco
|
|||
}
|
||||
}
|
||||
|
||||
@Test // see #7686.
|
||||
public void testIdsQueryWithInvalidValues() throws Exception {
|
||||
createIndex("test");
|
||||
indexRandom(true, false, client().prepareIndex("test", "type", "1").setSource("body", "foo"));
|
||||
|
||||
try {
|
||||
client().prepareSearch("test")
|
||||
.setTypes("type")
|
||||
.setQuery("{\n" +
|
||||
" \"ids\": {\n" +
|
||||
" \"values\": [[\"1\"]]\n" +
|
||||
" }\n" +
|
||||
"}")
|
||||
.get();
|
||||
fail("query is invalid and should have produced a parse exception");
|
||||
} catch (Exception e) {
|
||||
assertThat("query could not be parsed due to bad format: " + e.toString(),
|
||||
e.toString().contains("Illegal value for id, expecting a string or number, got: START_ARRAY"),
|
||||
equalTo(true));
|
||||
}
|
||||
}
|
||||
// NORELEASE This should be tested in SearchSourceBuilderTests
|
||||
// @Test // see #7686.
|
||||
// public void testIdsQueryWithInvalidValues() throws Exception {
|
||||
// createIndex("test");
|
||||
// indexRandom(true, false, client().prepareIndex("test", "type", "1").setSource("body", "foo"));
|
||||
//
|
||||
// try {
|
||||
// client().prepareSearch("test")
|
||||
// .setTypes("type")
|
||||
// .setQuery("{\n" +
|
||||
// " \"ids\": {\n" +
|
||||
// " \"values\": [[\"1\"]]\n" +
|
||||
// " }\n" +
|
||||
// "}")
|
||||
// .get();
|
||||
// fail("query is invalid and should have produced a parse exception");
|
||||
// } catch (Exception e) {
|
||||
// assertThat("query could not be parsed due to bad format: " + e.toString(),
|
||||
// e.toString().contains("Illegal value for id, expecting a string or number, got: START_ARRAY"),
|
||||
// equalTo(true));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -242,10 +242,12 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
|
|||
assertHitCount(searchResponse, 3l);
|
||||
assertSearchHits(searchResponse, "1", "2", "3");
|
||||
|
||||
// Sending a negative 'flags' value is the same as SimpleQueryStringFlag.ALL
|
||||
searchResponse = client().prepareSearch().setQuery("{\"simple_query_string\": {\"query\": \"foo bar\", \"flags\": -1}}").get();
|
||||
assertHitCount(searchResponse, 3l);
|
||||
assertSearchHits(searchResponse, "1", "2", "3");
|
||||
|
||||
// NORELEASE This should be tested in SimpleQueryStringQueryBuilderTests
|
||||
// // Sending a negative 'flags' value is the same as SimpleQueryStringFlag.ALL
|
||||
// searchResponse = client().prepareSearch().setQuery("{\"simple_query_string\": {\"query\": \"foo bar\", \"flags\": -1}}").get();
|
||||
// assertHitCount(searchResponse, 3l);
|
||||
// assertSearchHits(searchResponse, "1", "2", "3");
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
simpleQueryStringQuery("foo | bar")
|
||||
|
|
|
@ -21,11 +21,13 @@ package org.elasticsearch.search.timeout;
|
|||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.scriptQuery;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
|
@ -44,7 +46,7 @@ public class SearchTimeoutIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type", "1").setSource("field", "value").setRefresh(true).execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
.setTimeout("10ms")
|
||||
.setTimeout(new TimeValue(10, TimeUnit.MILLISECONDS))
|
||||
.setQuery(scriptQuery(new Script("Thread.sleep(500); return true;")))
|
||||
.execute().actionGet();
|
||||
assertThat(searchResponse.isTimedOut(), equalTo(true));
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.elasticsearch.client.FilterClient;
|
|||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -55,6 +56,7 @@ import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
|||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.TermsQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder;
|
||||
import org.elasticsearch.indices.cache.query.terms.TermsLookup;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
|
@ -273,14 +275,11 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase {
|
|||
.get();
|
||||
transportClient().admin().indices().prepareRefresh(queryIndex).get();
|
||||
|
||||
// custom content, not sure how to specify "script_id" otherwise in the API
|
||||
XContentBuilder builder = jsonBuilder().startObject().startObject("function_score").field("boost_mode", "replace").startArray("functions")
|
||||
.startObject().startObject("script_score").field("script_id", "my_script").field("lang", "groovy").endObject().endObject().endArray().endObject().endObject();
|
||||
|
||||
SearchResponse searchResponse = transportClient()
|
||||
.prepareSearch(queryIndex)
|
||||
.setQuery(builder)
|
||||
.get();
|
||||
.setQuery(
|
||||
QueryBuilders.functionScoreQuery().boostMode(CombineFunction.REPLACE)
|
||||
.add(new ScriptScoreFunctionBuilder(new Script("my_script", ScriptType.INDEXED, "groovy", null)))).get();
|
||||
assertNoFailures(searchResponse);
|
||||
assertHitCount(searchResponse, 1);
|
||||
assertThat(searchResponse.getHits().getMaxScore(), is(10.0f));
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
|
@ -64,9 +65,11 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
|
|||
if (source != null) {
|
||||
delete.source(source);
|
||||
} else {
|
||||
QuerySourceBuilder querySourceBuilder = RestActions.parseQuerySource(request);
|
||||
if (querySourceBuilder != null) {
|
||||
delete.source(querySourceBuilder);
|
||||
QueryBuilder<?> queryBuilder = RestActions.parseQuerySource(request);
|
||||
if (queryBuilder != null) {
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder();
|
||||
querySourceBuilder.setQuery(queryBuilder);
|
||||
delete.source(querySourceBuilder.buildAsBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue