ES 7.7.0, Getting the following exception, although "has_parent" query is valid and works in ES index, getting an exception when trying to parse using ES parser API
Output :
ssb = {"query":{"term":{"_tenant_id":{"value":"working","boost":1.0}}}}
Exception in thread "main" org.elasticsearch.common.xcontent.XContentParseException: [1:41] [bool] failed to parse field [must]
at org.elasticsearch.common.xcontent.ObjectParser.parseValue(ObjectParser.java:510)
at org.elasticsearch.common.xcontent.ObjectParser.parseArray(ObjectParser.java:502)
at org.elasticsearch.common.xcontent.ObjectParser.parseSub(ObjectParser.java:534)
at org.elasticsearch.common.xcontent.ObjectParser.parse(ObjectParser.java:319)
at org.elasticsearch.common.xcontent.ObjectParser.parse(ObjectParser.java:251)
at org.elasticsearch.index.query.BoolQueryBuilder.fromXContent(BoolQueryBuilder.java:297)
at org.elasticsearch.search.SearchModule.lambda$registerQuery$14(SearchModule.java:871)
at org.elasticsearch.common.xcontent.NamedXContentRegistry.parseNamedObject(NamedXContentRegistry.java:140)
at org.elasticsearch.common.xcontent.support.AbstractXContentParser.namedObject(AbstractXContentParser.java:385)
at org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:317)
at org.elasticsearch.search.builder.SearchSourceBuilder.parseXContent(SearchSourceBuilder.java:1098)
at org.elasticsearch.search.builder.SearchSourceBuilder.parseXContent(SearchSourceBuilder.java:1036)
at QMain.main(QMain.java:34)
Caused by: ParsingException[unknown query [has_parent]]; nested: NamedObjectNotFoundException[[1:41] unknown field [has_parent]];
at org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:321)
at org.elasticsearch.index.query.BoolQueryBuilder.lambda$static$1(BoolQueryBuilder.java:281)
at org.elasticsearch.common.xcontent.AbstractObjectParser.lambda$declareObjectArray$10(AbstractObjectParser.java:237)
at org.elasticsearch.common.xcontent.AbstractObjectParser.lambda$declareFieldArray$16(AbstractObjectParser.java:265)
at org.elasticsearch.common.xcontent.AbstractObjectParser.parseArray(AbstractObjectParser.java:357)
at org.elasticsearch.common.xcontent.AbstractObjectParser.lambda$declareFieldArray$17(AbstractObjectParser.java:265)
at org.elasticsearch.common.xcontent.ObjectParser.lambda$declareField$9(ObjectParser.java:381)
at org.elasticsearch.common.xcontent.ObjectParser.parseValue(ObjectParser.java:508)
... 12 more
Caused by: org.elasticsearch.common.xcontent.NamedObjectNotFoundException: [1:41] unknown field [has_parent]
at org.elasticsearch.common.xcontent.NamedXContentRegistry.parseNamedObject(NamedXContentRegistry.java:132)
at org.elasticsearch.common.xcontent.support.AbstractXContentParser.namedObject(AbstractXContentParser.java:385)
at org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:317)
... 19 more
Java code to reproduce issue:
SearchSourceBuilder ssb = new SearchSourceBuilder();
String query = null;
String working = "{\"query\":{\"term\":{\"_tenant_id\":\"working\"}}}";
String notWorking = "{\"query\":{\"bool\":{\"must\":[{\"has_parent\":{\"query\":{\"match_all\":{}},\"parent_type\":\"event_parent\"}}]}}}";
//query = working;
// Not working
query = notWorking;
SearchModule searchModule1 = new SearchModule(Settings.EMPTY, false, Collections.emptyList());
XContentParser parser1 = XContentFactory.xContent(XContentType.JSON).createParser(
new NamedXContentRegistry(searchModule1.getNamedXContents()),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, query);
ssb.parseXContent(parser1);
System.out.println("ssb = " + ssb.toString());