has_parent builder: exception message/param fix (#31182)

has_parent builder throws exception message that it expects a `type`
while parser excepts `parent_type`
This commit is contained in:
Nirmal Chidambaram 2018-06-30 18:17:37 +00:00 committed by Julie Tibshirani
parent 1a54bca712
commit c827a4e8e1
2 changed files with 6 additions and 6 deletions

View File

@ -58,7 +58,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
private static final ParseField QUERY_FIELD = new ParseField("query");
private static final ParseField TYPE_FIELD = new ParseField("parent_type");
private static final ParseField PARENT_TYPE_FIELD = new ParseField("parent_type");
private static final ParseField SCORE_FIELD = new ParseField("score");
private static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
@ -74,8 +74,8 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
}
private HasParentQueryBuilder(String type, QueryBuilder query, boolean score, InnerHitBuilder innerHitBuilder) {
this.type = requireValue(type, "[" + NAME + "] requires 'type' field");
this.query = requireValue(query, "[" + NAME + "] requires 'query' field");
this.type = requireValue(type, "[" + NAME + "] requires '" + PARENT_TYPE_FIELD.getPreferredName() + "' field");
this.query = requireValue(query, "[" + NAME + "] requires '" + QUERY_FIELD.getPreferredName() + "' field");
this.score = score;
this.innerHitBuilder = innerHitBuilder;
}
@ -201,7 +201,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
builder.startObject(NAME);
builder.field(QUERY_FIELD.getPreferredName());
query.toXContent(builder, params);
builder.field(TYPE_FIELD.getPreferredName(), type);
builder.field(PARENT_TYPE_FIELD.getPreferredName(), type);
builder.field(SCORE_FIELD.getPreferredName(), score);
builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped);
printBoostAndQueryName(builder);
@ -235,7 +235,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
"[has_parent] query does not support [" + currentFieldName + "]");
}
} else if (token.isValue()) {
if (TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
if (PARENT_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
parentType = parser.text();
} else if (SCORE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
score = parser.booleanValue();

View File

@ -183,7 +183,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase<HasParentQ
QueryBuilder query = new MatchAllQueryBuilder();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> hasParentQuery(null, query, false));
assertThat(e.getMessage(), equalTo("[has_parent] requires 'type' field"));
assertThat(e.getMessage(), equalTo("[has_parent] requires 'parent_type' field"));
e = expectThrows(IllegalArgumentException.class,
() -> hasParentQuery("foo", null, false));