|
@@ -18,6 +18,7 @@
|
|
|
*/
|
|
|
package org.elasticsearch.search.child;
|
|
|
|
|
|
+import org.apache.lucene.search.join.ScoreMode;
|
|
|
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
|
|
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
|
|
import org.elasticsearch.action.count.CountResponse;
|
|
@@ -26,6 +27,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.collect.HppcMaps;
|
|
|
import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
@@ -34,7 +36,6 @@ import org.elasticsearch.index.mapper.MergeMappingException;
|
|
|
import org.elasticsearch.index.query.HasChildQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
-import org.elasticsearch.index.query.ScoreType;
|
|
|
import org.elasticsearch.rest.RestStatus;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
@@ -74,7 +75,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|
|
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
|
|
|
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
|
|
|
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.weightFactorFunction;
|
|
|
-import static org.elasticsearch.test.StreamsUtils.copyToStringFromClasspath;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
|
@@ -293,11 +293,11 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
for (int i = 1; i <= 10; i++) {
|
|
|
logger.info("Round {}", i);
|
|
|
SearchResponse searchResponse = client().prepareSearch("test")
|
|
|
- .setQuery(constantScoreQuery(hasChildQuery("child", matchAllQuery()).scoreType("max")))
|
|
|
+ .setQuery(constantScoreQuery(hasChildQuery("child", matchAllQuery()).scoreMode("max")))
|
|
|
.get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
searchResponse = client().prepareSearch("test")
|
|
|
- .setQuery(constantScoreQuery(hasParentQuery("parent", matchAllQuery()).scoreType("score")))
|
|
|
+ .setQuery(constantScoreQuery(hasParentQuery("parent", matchAllQuery()).scoreMode("score")))
|
|
|
.get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
}
|
|
@@ -555,11 +555,11 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
client().prepareIndex("test", "child", "c1").setSource("c_field", "1").setParent(parentId).get();
|
|
|
refresh();
|
|
|
|
|
|
- CountResponse countResponse = client().prepareCount("test").setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreType("max"))
|
|
|
+ CountResponse countResponse = client().prepareCount("test").setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode("max"))
|
|
|
.get();
|
|
|
assertHitCount(countResponse, 1l);
|
|
|
|
|
|
- countResponse = client().prepareCount("test").setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreType("score"))
|
|
|
+ countResponse = client().prepareCount("test").setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreMode("score"))
|
|
|
.get();
|
|
|
assertHitCount(countResponse, 1l);
|
|
|
|
|
@@ -586,20 +586,20 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
|
|
|
SearchResponse searchResponse = client().prepareSearch("test")
|
|
|
.setExplain(true)
|
|
|
- .setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreType("max"))
|
|
|
+ .setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode("max"))
|
|
|
.get();
|
|
|
assertHitCount(searchResponse, 1l);
|
|
|
assertThat(searchResponse.getHits().getAt(0).explanation().getDescription(), equalTo("Score based on join value p1"));
|
|
|
|
|
|
searchResponse = client().prepareSearch("test")
|
|
|
.setExplain(true)
|
|
|
- .setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreType("score"))
|
|
|
+ .setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreMode("score"))
|
|
|
.get();
|
|
|
assertHitCount(searchResponse, 1l);
|
|
|
assertThat(searchResponse.getHits().getAt(0).explanation().getDescription(), equalTo("Score based on join value p1"));
|
|
|
|
|
|
ExplainResponse explainResponse = client().prepareExplain("test", "parent", parentId)
|
|
|
- .setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreType("max"))
|
|
|
+ .setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode("max"))
|
|
|
.get();
|
|
|
assertThat(explainResponse.isExists(), equalTo(true));
|
|
|
assertThat(explainResponse.getExplanation().getDetails()[0].getDescription(), equalTo("Score based on join value p1"));
|
|
@@ -677,7 +677,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
"child",
|
|
|
QueryBuilders.functionScoreQuery(matchQuery("c_field2", 0),
|
|
|
scriptFunction(new Script("doc['c_field1'].value")))
|
|
|
- .boostMode(CombineFunction.REPLACE.getName())).scoreType("sum")).get();
|
|
|
+ .boostMode(CombineFunction.REPLACE.getName())).scoreMode("total")).get();
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("1"));
|
|
@@ -694,7 +694,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
"child",
|
|
|
QueryBuilders.functionScoreQuery(matchQuery("c_field2", 0),
|
|
|
scriptFunction(new Script("doc['c_field1'].value")))
|
|
|
- .boostMode(CombineFunction.REPLACE.getName())).scoreType("max")).get();
|
|
|
+ .boostMode(CombineFunction.REPLACE.getName())).scoreMode("max")).get();
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
@@ -711,7 +711,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
"child",
|
|
|
QueryBuilders.functionScoreQuery(matchQuery("c_field2", 0),
|
|
|
scriptFunction(new Script("doc['c_field1'].value")))
|
|
|
- .boostMode(CombineFunction.REPLACE.getName())).scoreType("avg")).get();
|
|
|
+ .boostMode(CombineFunction.REPLACE.getName())).scoreMode("avg")).get();
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
@@ -728,7 +728,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
"parent",
|
|
|
QueryBuilders.functionScoreQuery(matchQuery("p_field1", "p_value3"),
|
|
|
scriptFunction(new Script("doc['p_field2'].value")))
|
|
|
- .boostMode(CombineFunction.REPLACE.getName())).scoreType("score"))
|
|
|
+ .boostMode(CombineFunction.REPLACE.getName())).scoreMode("score"))
|
|
|
.addSort(SortBuilders.fieldSort("c_field3")).addSort(SortBuilders.scoreSort()).get();
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(7l));
|
|
@@ -768,7 +768,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertNoFailures(response);
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
|
|
|
- response = client().prepareSearch("test").setQuery(QueryBuilders.hasChildQuery("child", matchQuery("text", "value")).scoreType("max"))
|
|
|
+ response = client().prepareSearch("test").setQuery(QueryBuilders.hasChildQuery("child", matchQuery("text", "value")).scoreMode("max"))
|
|
|
.get();
|
|
|
assertNoFailures(response);
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
@@ -777,7 +777,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertNoFailures(response);
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
|
|
|
- response = client().prepareSearch("test").setQuery(QueryBuilders.hasParentQuery("child", matchQuery("text", "value")).scoreType("score"))
|
|
|
+ response = client().prepareSearch("test").setQuery(QueryBuilders.hasParentQuery("child", matchQuery("text", "value")).scoreMode("score"))
|
|
|
.get();
|
|
|
assertNoFailures(response);
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
@@ -864,7 +864,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
SearchType[] searchTypes = new SearchType[]{SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH};
|
|
|
for (SearchType searchType : searchTypes) {
|
|
|
SearchResponse searchResponse = client().prepareSearch("test").setSearchType(searchType)
|
|
|
- .setQuery(hasChildQuery("child", prefixQuery("c_field", "c")).scoreType("max")).addSort("p_field", SortOrder.ASC)
|
|
|
+ .setQuery(hasChildQuery("child", prefixQuery("c_field", "c")).scoreMode("max")).addSort("p_field", SortOrder.ASC)
|
|
|
.setSize(5).get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(10L));
|
|
@@ -875,7 +875,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(searchResponse.getHits().hits()[4].id(), equalTo("p004"));
|
|
|
|
|
|
searchResponse = client().prepareSearch("test").setSearchType(searchType)
|
|
|
- .setQuery(hasParentQuery("parent", prefixQuery("p_field", "p")).scoreType("score")).addSort("c_field", SortOrder.ASC)
|
|
|
+ .setQuery(hasParentQuery("parent", prefixQuery("p_field", "p")).scoreMode("score")).addSort("c_field", SortOrder.ASC)
|
|
|
.setSize(5).get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(500L));
|
|
@@ -907,7 +907,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
refresh();
|
|
|
|
|
|
SearchResponse searchResponse = client().prepareSearch("test")
|
|
|
- .setQuery(hasChildQuery("child", termQuery("c_field", "yellow")).scoreType("sum")).get();
|
|
|
+ .setQuery(hasChildQuery("child", termQuery("c_field", "yellow")).scoreMode("total")).get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
|
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("p1"));
|
|
@@ -917,7 +917,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
.prepareSearch("test")
|
|
|
.setQuery(
|
|
|
boolQuery().must(matchQuery("c_field", "x")).must(
|
|
|
- hasParentQuery("parent", termQuery("p_field", "p_value2")).scoreType("score"))).get();
|
|
|
+ hasParentQuery("parent", termQuery("p_field", "p_value2")).scoreMode("score"))).get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("c3"));
|
|
@@ -932,7 +932,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
client().admin().indices().prepareRefresh("test").get();
|
|
|
}
|
|
|
|
|
|
- searchResponse = client().prepareSearch("test").setQuery(hasChildQuery("child", termQuery("c_field", "yellow")).scoreType("sum"))
|
|
|
+ searchResponse = client().prepareSearch("test").setQuery(hasChildQuery("child", termQuery("c_field", "yellow")).scoreMode("total"))
|
|
|
.get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
|
@@ -943,7 +943,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
.prepareSearch("test")
|
|
|
.setQuery(
|
|
|
boolQuery().must(matchQuery("c_field", "x")).must(
|
|
|
- hasParentQuery("parent", termQuery("p_field", "p_value2")).scoreType("score"))).get();
|
|
|
+ hasParentQuery("parent", termQuery("p_field", "p_value2")).scoreMode("score"))).get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(searchResponse.getHits().getAt(0).id(), Matchers.anyOf(equalTo("c3"), equalTo("c4")));
|
|
@@ -968,7 +968,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
client().prepareIndex("test", "child", "c5").setSource("c_field", "x").setParent("p2").get();
|
|
|
refresh();
|
|
|
|
|
|
- SearchResponse searchResponse = client().prepareSearch("test").setQuery(hasChildQuery("child", matchAllQuery()).scoreType("sum"))
|
|
|
+ SearchResponse searchResponse = client().prepareSearch("test").setQuery(hasChildQuery("child", matchAllQuery()).scoreMode("total"))
|
|
|
.setMinScore(3) // Score needs to be 3 or above!
|
|
|
.get();
|
|
|
assertNoFailures(searchResponse);
|
|
@@ -1237,15 +1237,15 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
client().prepareIndex("test", "child", "c3").setParent("p2").setSource("c_field", "red").get();
|
|
|
refresh();
|
|
|
|
|
|
- String scoreMode = ScoreType.values()[getRandom().nextInt(ScoreType.values().length)].name().toLowerCase(Locale.ROOT);
|
|
|
+ String scoreMode = ScoreMode.values()[getRandom().nextInt(ScoreMode.values().length)].name().toLowerCase(Locale.ROOT);
|
|
|
SearchResponse searchResponse = client().prepareSearch("test")
|
|
|
- .setQuery(boolQuery().must(QueryBuilders.hasChildQuery("child", termQuery("c_field", "blue")).scoreType(scoreMode)).filter(notQuery(termQuery("p_field", "3"))))
|
|
|
+ .setQuery(boolQuery().must(QueryBuilders.hasChildQuery("child", termQuery("c_field", "blue")).scoreMode(scoreMode)).filter(notQuery(termQuery("p_field", "3"))))
|
|
|
.get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
|
|
|
|
|
searchResponse = client().prepareSearch("test")
|
|
|
- .setQuery(boolQuery().must(QueryBuilders.hasChildQuery("child", termQuery("c_field", "red")).scoreType(scoreMode)).filter(notQuery(termQuery("p_field", "3"))))
|
|
|
+ .setQuery(boolQuery().must(QueryBuilders.hasChildQuery("child", termQuery("c_field", "red")).scoreMode(scoreMode)).filter(notQuery(termQuery("p_field", "3"))))
|
|
|
.get();
|
|
|
assertNoFailures(searchResponse);
|
|
|
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
|
@@ -1263,13 +1263,13 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
client().prepareIndex("test", "child", "c1").setSource("c_field", "1").setParent(parentId).get();
|
|
|
refresh();
|
|
|
|
|
|
- SearchResponse searchResponse = client().prepareSearch("test").setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreType("max").queryName("test"))
|
|
|
+ SearchResponse searchResponse = client().prepareSearch("test").setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode("max").queryName("test"))
|
|
|
.get();
|
|
|
assertHitCount(searchResponse, 1l);
|
|
|
assertThat(searchResponse.getHits().getAt(0).getMatchedQueries().length, equalTo(1));
|
|
|
assertThat(searchResponse.getHits().getAt(0).getMatchedQueries()[0], equalTo("test"));
|
|
|
|
|
|
- searchResponse = client().prepareSearch("test").setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreType("score").queryName("test"))
|
|
|
+ searchResponse = client().prepareSearch("test").setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreMode("score").queryName("test"))
|
|
|
.get();
|
|
|
assertHitCount(searchResponse, 1l);
|
|
|
assertThat(searchResponse.getHits().getAt(0).getMatchedQueries().length, equalTo(1));
|
|
@@ -1311,7 +1311,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
|
|
|
try {
|
|
|
client().prepareSearch("test")
|
|
|
- .setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreType("max"))
|
|
|
+ .setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode("max"))
|
|
|
.get();
|
|
|
fail();
|
|
|
} catch (SearchPhaseExecutionException e) {
|
|
@@ -1329,7 +1329,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
|
|
|
try {
|
|
|
client().prepareSearch("test")
|
|
|
- .setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreType("score"))
|
|
|
+ .setQuery(hasParentQuery("parent", termQuery("p_field", "1")).scoreMode("score"))
|
|
|
.get();
|
|
|
fail();
|
|
|
} catch (SearchPhaseExecutionException e) {
|
|
@@ -1579,28 +1579,23 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
return indexBuilders;
|
|
|
}
|
|
|
|
|
|
- private SearchResponse minMaxQuery(String scoreType, int minChildren, int maxChildren) throws SearchPhaseExecutionException {
|
|
|
- return client()
|
|
|
- .prepareSearch("test")
|
|
|
- .setQuery(
|
|
|
- QueryBuilders
|
|
|
- .hasChildQuery(
|
|
|
- "child",
|
|
|
- QueryBuilders.functionScoreQuery(constantScoreQuery(QueryBuilders.termQuery("foo", "two"))).boostMode("replace").scoreMode("sum")
|
|
|
- .add(QueryBuilders.matchAllQuery(), weightFactorFunction(1))
|
|
|
- .add(QueryBuilders.termQuery("foo", "three"), weightFactorFunction(1))
|
|
|
- .add(QueryBuilders.termQuery("foo", "four"), weightFactorFunction(1))).scoreType(scoreType)
|
|
|
- .minChildren(minChildren).maxChildren(maxChildren))
|
|
|
- .addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
|
|
|
- }
|
|
|
+ private SearchResponse minMaxQuery(String scoreMode, int minChildren, Integer maxChildren) throws SearchPhaseExecutionException {
|
|
|
+ HasChildQueryBuilder hasChildQuery = hasChildQuery(
|
|
|
+ "child",
|
|
|
+ QueryBuilders.functionScoreQuery(constantScoreQuery(QueryBuilders.termQuery("foo", "two"))).boostMode("replace").scoreMode("sum")
|
|
|
+ .add(QueryBuilders.matchAllQuery(), weightFactorFunction(1))
|
|
|
+ .add(QueryBuilders.termQuery("foo", "three"), weightFactorFunction(1))
|
|
|
+ .add(QueryBuilders.termQuery("foo", "four"), weightFactorFunction(1))).scoreMode(scoreMode)
|
|
|
+ .minChildren(minChildren);
|
|
|
+
|
|
|
+ if (maxChildren != null) {
|
|
|
+ hasChildQuery.maxChildren(maxChildren);
|
|
|
+ }
|
|
|
|
|
|
- private SearchResponse minMaxFilter(int minChildren, int maxChildren) throws SearchPhaseExecutionException {
|
|
|
return client()
|
|
|
.prepareSearch("test")
|
|
|
- .setQuery(
|
|
|
- QueryBuilders.constantScoreQuery(QueryBuilders.hasChildQuery("child", termQuery("foo", "two"))
|
|
|
- .minChildren(minChildren).maxChildren(maxChildren)))
|
|
|
- .addSort("id", SortOrder.ASC).setTrackScores(true).get();
|
|
|
+ .setQuery(hasChildQuery)
|
|
|
+ .addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -1614,7 +1609,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
SearchResponse response;
|
|
|
|
|
|
// Score mode = NONE
|
|
|
- response = minMaxQuery("none", 0, 0);
|
|
|
+ response = minMaxQuery("none", 0, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
@@ -1624,7 +1619,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("none", 1, 0);
|
|
|
+ response = minMaxQuery("none", 1, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
@@ -1634,7 +1629,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("none", 2, 0);
|
|
|
+ response = minMaxQuery("none", 2, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
@@ -1642,13 +1637,13 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[1].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("none", 3, 0);
|
|
|
+ response = minMaxQuery("none", 3, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("none", 4, 0);
|
|
|
+ response = minMaxQuery("none", 4, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
|
|
@@ -1693,8 +1688,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(e.toString(), containsString("[has_child] 'max_children' is less than 'min_children'"));
|
|
|
}
|
|
|
|
|
|
- // Score mode = SUM
|
|
|
- response = minMaxQuery("sum", 0, 0);
|
|
|
+ // Score mode = TOTAL
|
|
|
+ response = minMaxQuery("total", 0, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1704,7 +1699,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 1, 0);
|
|
|
+ response = minMaxQuery("total", 1, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1714,7 +1709,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 2, 0);
|
|
|
+ response = minMaxQuery("total", 2, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1722,17 +1717,17 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
assertThat(response.getHits().hits()[1].score(), equalTo(3f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 3, 0);
|
|
|
+ response = minMaxQuery("total", 3, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[0].score(), equalTo(6f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 4, 0);
|
|
|
+ response = minMaxQuery("total", 4, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
|
|
|
- response = minMaxQuery("sum", 0, 4);
|
|
|
+ response = minMaxQuery("total", 0, 4);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1742,7 +1737,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 0, 3);
|
|
|
+ response = minMaxQuery("total", 0, 3);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1752,7 +1747,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 0, 2);
|
|
|
+ response = minMaxQuery("total", 0, 2);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
@@ -1760,21 +1755,21 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[1].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("sum", 2, 2);
|
|
|
+ response = minMaxQuery("total", 2, 2);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
|
assertThat(response.getHits().hits()[0].score(), equalTo(3f));
|
|
|
|
|
|
try {
|
|
|
- response = minMaxQuery("sum", 3, 2);
|
|
|
+ response = minMaxQuery("total", 3, 2);
|
|
|
fail();
|
|
|
} catch (SearchPhaseExecutionException e) {
|
|
|
assertThat(e.toString(), containsString("[has_child] 'max_children' is less than 'min_children'"));
|
|
|
}
|
|
|
|
|
|
// Score mode = MAX
|
|
|
- response = minMaxQuery("max", 0, 0);
|
|
|
+ response = minMaxQuery("max", 0, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1784,7 +1779,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("max", 1, 0);
|
|
|
+ response = minMaxQuery("max", 1, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1794,7 +1789,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("max", 2, 0);
|
|
|
+ response = minMaxQuery("max", 2, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1802,13 +1797,13 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
assertThat(response.getHits().hits()[1].score(), equalTo(2f));
|
|
|
|
|
|
- response = minMaxQuery("max", 3, 0);
|
|
|
+ response = minMaxQuery("max", 3, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[0].score(), equalTo(3f));
|
|
|
|
|
|
- response = minMaxQuery("max", 4, 0);
|
|
|
+ response = minMaxQuery("max", 4, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
|
|
@@ -1854,7 +1849,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
}
|
|
|
|
|
|
// Score mode = AVG
|
|
|
- response = minMaxQuery("avg", 0, 0);
|
|
|
+ response = minMaxQuery("avg", 0, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1864,7 +1859,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("avg", 1, 0);
|
|
|
+ response = minMaxQuery("avg", 1, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1874,7 +1869,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[2].id(), equalTo("2"));
|
|
|
assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
|
|
|
- response = minMaxQuery("avg", 2, 0);
|
|
|
+ response = minMaxQuery("avg", 2, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
@@ -1882,13 +1877,13 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
assertThat(response.getHits().hits()[1].score(), equalTo(1.5f));
|
|
|
|
|
|
- response = minMaxQuery("avg", 3, 0);
|
|
|
+ response = minMaxQuery("avg", 3, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
|
assertThat(response.getHits().hits()[0].score(), equalTo(2f));
|
|
|
|
|
|
- response = minMaxQuery("avg", 4, 0);
|
|
|
+ response = minMaxQuery("avg", 4, null);
|
|
|
|
|
|
assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
|
|
@@ -1932,87 +1927,6 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|
|
} catch (SearchPhaseExecutionException e) {
|
|
|
assertThat(e.toString(), containsString("[has_child] 'max_children' is less than 'min_children'"));
|
|
|
}
|
|
|
-
|
|
|
- // HasChildFilter
|
|
|
- response = minMaxFilter(0, 0);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[2].id(), equalTo("4"));
|
|
|
- assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(1, 0);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[2].id(), equalTo("4"));
|
|
|
- assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(2, 0);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[1].id(), equalTo("4"));
|
|
|
- assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(3, 0);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("4"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(4, 0);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(0l));
|
|
|
-
|
|
|
- response = minMaxFilter(0, 4);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[2].id(), equalTo("4"));
|
|
|
- assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(0, 3);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(3l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[2].id(), equalTo("4"));
|
|
|
- assertThat(response.getHits().hits()[2].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(0, 2);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(2l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("2"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
- assertThat(response.getHits().hits()[1].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[1].score(), equalTo(1f));
|
|
|
-
|
|
|
- response = minMaxFilter(2, 2);
|
|
|
-
|
|
|
- assertThat(response.getHits().totalHits(), equalTo(1l));
|
|
|
- assertThat(response.getHits().hits()[0].id(), equalTo("3"));
|
|
|
- assertThat(response.getHits().hits()[0].score(), equalTo(1f));
|
|
|
-
|
|
|
- try {
|
|
|
- response = minMaxFilter(3, 2);
|
|
|
- fail();
|
|
|
- } catch (SearchPhaseExecutionException e) {
|
|
|
- assertThat(e.toString(), containsString("[has_child] 'max_children' is less than 'min_children'"));
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Test
|