diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java index a57008056b4..03556c12b7f 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -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 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 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"))); diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java index 72057a9cf51..ce094d0c8d8 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java @@ -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()); } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java b/core/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java index 677f3af4508..512b3b7d5bf 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java @@ -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")); diff --git a/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java b/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java index 7cfe7caf3fd..1fc84007284 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/exists/RestExistsAction.java @@ -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")); diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 03a33e0c96b..b18e64207ba 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -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)) ); } diff --git a/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java b/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java index 674aa6902b0..464870ac4c6 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java +++ b/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java @@ -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; } /** diff --git a/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java b/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java index 1a0579445f8..578accbe4e4 100644 --- a/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java @@ -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(); diff --git a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java index 0c9fc74cb5d..bbfd12d184a 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java +++ b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryIT.java @@ -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 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); diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java index e2859708aba..cfde7a81485 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java @@ -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 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")); diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java index 4548fbd7d0e..4a2c8bd95c5 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java @@ -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 diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java index 670d31739b1..64b42a0d034 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java @@ -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 { diff --git a/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java index 4134c4f2941..c44040ff644 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java @@ -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("").postTags("").fragmentSize(1).numOfFragments(1) + .highlighter(highlight().order("score").preTags("").postTags("").fragmentSize(1).numOfFragments(1) .field(new HighlightBuilder.Field("field1").numOfFragments(2)) .field(new HighlightBuilder.Field("field2").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field*").preTags("").postTags("").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("").postTags("")); + .highlighter(highlight().field("field1").order("score").preTags("").postTags("")); 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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field1").order("score").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("").requireFieldMatch(false)); searchResponse = client().prepareSearch("test").setSource(source).get(); assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick 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("").postTags("")); + .highlighter(highlight().field("field1", 100, 0).order("score").preTags("").postTags("")); 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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field1", 100, 0).order("score").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field2", 100, 0).order("score").preTags("").postTags("").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("").postTags("").requireFieldMatch(false)); + .highlighter(highlight().field("field2", 100, 0).order("score").preTags("").postTags("").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("").postTags("")); + .highlighter(highlight().highlighterType("fvh").field("field1", 20, 1).order("score").preTags("").postTags("")); SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field1", 0, 1, containsString("t")); 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("").postTags("")); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get(); assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown 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("").postTags("")); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field0").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field1").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field3").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field4").order("score").preTags("").postTags("")); searchResponse = client().search(searchRequest("test").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(equalTo("The quick browse button is a fancy thing, right bro?"), equalTo("The quick brown 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("").postTags("")); + .highlighter(highlight().field("field4").order("score").preTags("").postTags("")); searchResponse = client().search(searchRequest("test").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field4", 0, 1, equalTo("a quick fast blue car")); @@ -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("").postTags("")); + .highlighter(highlight().field("field1").preTags("").postTags("")); SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("this is a test")); @@ -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("").postTags("")); + .highlighter(highlight().field("field1").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); 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("").postTags("")); + .highlighter(highlight().field("field2").preTags("").postTags("")); 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("").postTags("").highlighterType("highlighter").requireFieldMatch(false)); + .highlighter(highlight().field("field2").preTags("").postTags("").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("").postTags(""))); 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("").postTags(""))); 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("").postTags(""))); 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("").postTags("")); + .highlighter(highlight().field("field2").preTags("").postTags("")); SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown 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("").postTags("")); + .highlighter(highlight().field("field2").preTags("").postTags("")); 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 quick 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 quick 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 quick 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 quick 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("aaab")); @@ -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 quick 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 photography 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 photography 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 photography 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 photography word will get highlighted")); } diff --git a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 83a8008213f..ac364a81479 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -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)); +// } +// } } diff --git a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java index bf3e458cb5b..55a9ff00d5b 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java @@ -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") diff --git a/core/src/test/java/org/elasticsearch/search/timeout/SearchTimeoutIT.java b/core/src/test/java/org/elasticsearch/search/timeout/SearchTimeoutIT.java index 6197224f3b2..5a16d740cc8 100644 --- a/core/src/test/java/org/elasticsearch/search/timeout/SearchTimeoutIT.java +++ b/core/src/test/java/org/elasticsearch/search/timeout/SearchTimeoutIT.java @@ -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)); diff --git a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java index 04e41548b99..c4a2e67d87f 100644 --- a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java @@ -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)); diff --git a/plugins/delete-by-query/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java b/plugins/delete-by-query/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java index 251953da668..29533f16217 100644 --- a/plugins/delete-by-query/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java +++ b/plugins/delete-by-query/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java @@ -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()); } } }