Skip to content

Commit 58d3c70

Browse files
nirmalcjimczi
authored andcommitted
has_parent builder: exception message/param fix (#31182)
has_parent builder throws exception message that it expects a `type` while parser excepts `parent_type`
1 parent 1e4440a commit 58d3c70

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

modules/parent-join/src/main/java/org/elasticsearch/join/query/HasParentQueryBuilder.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
6464
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
6565

6666
private static final ParseField QUERY_FIELD = new ParseField("query");
67-
private static final ParseField TYPE_FIELD = new ParseField("parent_type");
67+
private static final ParseField PARENT_TYPE_FIELD = new ParseField("parent_type");
6868
private static final ParseField SCORE_FIELD = new ParseField("score");
6969
private static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
7070
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
@@ -80,8 +80,8 @@ public HasParentQueryBuilder(String type, QueryBuilder query, boolean score) {
8080
}
8181

8282
private HasParentQueryBuilder(String type, QueryBuilder query, boolean score, InnerHitBuilder innerHitBuilder) {
83-
this.type = requireValue(type, "[" + NAME + "] requires 'type' field");
84-
this.query = requireValue(query, "[" + NAME + "] requires 'query' field");
83+
this.type = requireValue(type, "[" + NAME + "] requires '" + PARENT_TYPE_FIELD.getPreferredName() + "' field");
84+
this.query = requireValue(query, "[" + NAME + "] requires '" + QUERY_FIELD.getPreferredName() + "' field");
8585
this.score = score;
8686
this.innerHitBuilder = innerHitBuilder;
8787
}
@@ -274,7 +274,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
274274
builder.startObject(NAME);
275275
builder.field(QUERY_FIELD.getPreferredName());
276276
query.toXContent(builder, params);
277-
builder.field(TYPE_FIELD.getPreferredName(), type);
277+
builder.field(PARENT_TYPE_FIELD.getPreferredName(), type);
278278
builder.field(SCORE_FIELD.getPreferredName(), score);
279279
builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped);
280280
printBoostAndQueryName(builder);
@@ -308,7 +308,7 @@ public static HasParentQueryBuilder fromXContent(XContentParser parser) throws I
308308
"[has_parent] query does not support [" + currentFieldName + "]");
309309
}
310310
} else if (token.isValue()) {
311-
if (TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
311+
if (PARENT_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
312312
parentType = parser.text();
313313
} else if (SCORE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
314314
score = parser.booleanValue();

modules/parent-join/src/test/java/org/elasticsearch/join/query/HasParentQueryBuilderTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void testIllegalValues() throws IOException {
183183
QueryBuilder query = new MatchAllQueryBuilder();
184184
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
185185
() -> hasParentQuery(null, query, false));
186-
assertThat(e.getMessage(), equalTo("[has_parent] requires 'type' field"));
186+
assertThat(e.getMessage(), equalTo("[has_parent] requires 'parent_type' field"));
187187

188188
e = expectThrows(IllegalArgumentException.class,
189189
() -> hasParentQuery("foo", null, false));

0 commit comments

Comments
 (0)