nested / parent child: Removed `total` score mode in favour of `sum` score mode.

Closes #17083
This commit is contained in:
Martijn van Groningen 2016-03-17 17:29:10 +01:00
parent 69ff402b62
commit 1dd2be81c3
6 changed files with 22 additions and 20 deletions

View File

@ -189,7 +189,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
builder.field(HasChildQueryParser.QUERY_FIELD.getPreferredName());
query.toXContent(builder, params);
builder.field(HasChildQueryParser.TYPE_FIELD.getPreferredName(), type);
builder.field(HasChildQueryParser.SCORE_MODE_FIELD.getPreferredName(), scoreMode.name().toLowerCase(Locale.ROOT));
builder.field(HasChildQueryParser.SCORE_MODE_FIELD.getPreferredName(), HasChildQueryParser.scoreModeAsString(scoreMode));
builder.field(HasChildQueryParser.MIN_CHILDREN_FIELD.getPreferredName(), minChildren);
builder.field(HasChildQueryParser.MAX_CHILDREN_FIELD.getPreferredName(), maxChildren);
printBoostAndQueryName(builder);

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.support.QueryInnerHits;
import java.io.IOException;
import java.util.Locale;
/**
* A query parser for <tt>has_child</tt> queries.
@ -104,12 +105,21 @@ public class HasChildQueryParser implements QueryParser<HasChildQueryBuilder> {
return ScoreMode.Max;
} else if ("avg".equals(scoreModeString)) {
return ScoreMode.Avg;
} else if ("total".equals(scoreModeString)) {
} else if ("sum".equals(scoreModeString)) {
return ScoreMode.Total;
}
throw new IllegalArgumentException("No score mode for child query [" + scoreModeString + "] found");
}
public static String scoreModeAsString(ScoreMode scoreMode) {
if (scoreMode == ScoreMode.Total) {
// Lucene uses 'total' but 'sum' is more consistent with other elasticsearch APIs
return "sum";
} else {
return scoreMode.name().toLowerCase(Locale.ROOT);
}
}
@Override
public HasChildQueryBuilder getBuilderPrototype() {
return HasChildQueryBuilder.PROTOTYPE;

View File

@ -121,7 +121,7 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
query.toXContent(builder, params);
builder.field(NestedQueryParser.PATH_FIELD.getPreferredName(), path);
if (scoreMode != null) {
builder.field(NestedQueryParser.SCORE_MODE_FIELD.getPreferredName(), scoreMode.name().toLowerCase(Locale.ROOT));
builder.field(NestedQueryParser.SCORE_MODE_FIELD.getPreferredName(), HasChildQueryParser.scoreModeAsString(scoreMode));
}
printBoostAndQueryName(builder);
if (queryInnerHits != null) {

View File

@ -68,20 +68,7 @@ public class NestedQueryParser implements QueryParser<NestedQueryBuilder> {
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) {
boost = parser.floatValue();
} else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) {
String sScoreMode = parser.text();
if ("avg".equals(sScoreMode)) {
scoreMode = ScoreMode.Avg;
} else if ("min".equals(sScoreMode)) {
scoreMode = ScoreMode.Min;
} else if ("max".equals(sScoreMode)) {
scoreMode = ScoreMode.Max;
} else if ("total".equals(sScoreMode) || "sum".equals(sScoreMode)) {
scoreMode = ScoreMode.Total;
} else if ("none".equals(sScoreMode)) {
scoreMode = ScoreMode.None;
} else {
throw new ParsingException(parser.getTokenLocation(), "illegal score_mode for nested query [" + sScoreMode + "]");
}
scoreMode = HasChildQueryParser.parseScoreMode(parser.text());
} else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) {
queryName = parser.text();
} else {

View File

@ -27,22 +27,27 @@ import static org.hamcrest.Matchers.is;
public class HasChildQueryParserTests extends ESTestCase {
public void testMinFromString() {
assertThat("fromString(min) != MIN", ScoreMode.Min, equalTo(HasChildQueryParser.parseScoreMode("min")));
assertThat("min", equalTo(HasChildQueryParser.scoreModeAsString(ScoreMode.Min)));
}
public void testMaxFromString() {
assertThat("fromString(max) != MAX", ScoreMode.Max, equalTo(HasChildQueryParser.parseScoreMode("max")));
assertThat("max", equalTo(HasChildQueryParser.scoreModeAsString(ScoreMode.Max)));
}
public void testAvgFromString() {
assertThat("fromString(avg) != AVG", ScoreMode.Avg, equalTo(HasChildQueryParser.parseScoreMode("avg")));
assertThat("avg", equalTo(HasChildQueryParser.scoreModeAsString(ScoreMode.Avg)));
}
public void testSumFromString() {
assertThat("fromString(total) != SUM", ScoreMode.Total, equalTo(HasChildQueryParser.parseScoreMode("total")));
assertThat("fromString(total) != SUM", ScoreMode.Total, equalTo(HasChildQueryParser.parseScoreMode("sum")));
assertThat("sum", equalTo(HasChildQueryParser.scoreModeAsString(ScoreMode.Total)));
}
public void testNoneFromString() {
assertThat("fromString(none) != NONE", ScoreMode.None, equalTo(HasChildQueryParser.parseScoreMode("none")));
assertThat("none", equalTo(HasChildQueryParser.scoreModeAsString(ScoreMode.None)));
}
/**

View File

@ -113,8 +113,8 @@ in favour of `query` and `no_match_query`.
* The `collect_payloads` parameter of the `span_near` query has been deprecated. Payloads will be loaded when needed.
* The `score_type` parameter to the `has_child` and `has_parent` queries has been removed in favour of `score_mode`.
Also, the `sum` score mode has been removed in favour of the `total` mode.
* The `score_type` parameter to the `nested`, has_child` and `has_parent` queries has been removed in favour of `score_mode`.
Also, the `total` score mode has been removed in favour of the `sum` mode.
* When the `max_children` parameter was set to `0` on the `has_child` query
then there was no upper limit on how many child documents were allowed to