用了Elasticsearch,一口气上5T

Elasticsearch 6.5.4 ParsingException[no [query] registered for [has_child]]

Elasticsearch | 作者 llnjava | 发布于2020年03月29日 | 阅读数:332

由于业务需要使用haschild做关联查询,接口接收查询json串后转换为SearchSourceBuilder,但是提示ParsingException[no [query] registered for [has_child]]
查询json如下:
{
"from" : 0,
"size" : 30,
"query" : {
"bool" : {
"should" : [ {
"multi_match" : {
"query" : "iphone",
"fields" : [ "shopName^4.0", "gysName^3.0" ]
}
}, {
"has_child" : {
"query" : {
"multi_match" : {
"query" : "iphone",
"fields" : [ "skuName^2.0", "brandNameChEn^1.0", "cName" ]
}
},
"type" : "sku"
}
} ]
}
},
"highlight" : {
"pre_tags" : [ "<em>" ],
"post_tags" : [ "</em>" ],
"fields" : {
"shopName" : { }
}
}
}

转换代码如下:
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
try {
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList());
NamedXContentRegistry registry = new NamedXContentRegistry(searchModule.getNamedXContents());
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(registry,LoggingDeprecationHandler.INSTANCE,source);
searchSourceBuilder.parseXContent(parser);
} catch (Exception e) {
e.printStackTrace();
throw SearchException.ES_REMOVE_FAIL.newInstance("解析查询条件异常,source:%s,error:%s",source,e);
}
return searchSourceBuilder;
找了一些资料,并查看了源码,发现SearchModule类中并未注册haschildquery类,不知道这种情况如何处理?请帮忙想想办法,多谢!
已邀请:

llnjava

赞同来自:

以下是SearchModule注册querybuilder的代码,并未有haschildquerybuilder
private void registerQueryParsers(List<SearchPlugin> plugins) {
this.registerQuery(new QuerySpec("match", MatchQueryBuilder::new, MatchQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("match_phrase", MatchPhraseQueryBuilder::new, MatchPhraseQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("match_phrase_prefix", MatchPhrasePrefixQueryBuilder::new, MatchPhrasePrefixQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("multi_match", MultiMatchQueryBuilder::new, MultiMatchQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("nested", NestedQueryBuilder::new, NestedQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("dis_max", DisMaxQueryBuilder::new, DisMaxQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("ids", IdsQueryBuilder::new, IdsQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("match_all", MatchAllQueryBuilder::new, MatchAllQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("query_string", QueryStringQueryBuilder::new, QueryStringQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("boosting", BoostingQueryBuilder::new, BoostingQueryBuilder::fromXContent));
BooleanQuery.setMaxClauseCount((Integer)INDICES_MAX_CLAUSE_COUNT_SETTING.get(this.settings));
this.registerQuery(new QuerySpec("bool", BoolQueryBuilder::new, BoolQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("term", TermQueryBuilder::new, TermQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("terms", TermsQueryBuilder::new, TermsQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("fuzzy", FuzzyQueryBuilder::new, FuzzyQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("regexp", RegexpQueryBuilder::new, RegexpQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("range", RangeQueryBuilder::new, RangeQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("prefix", PrefixQueryBuilder::new, PrefixQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("wildcard", WildcardQueryBuilder::new, WildcardQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("constant_score", ConstantScoreQueryBuilder::new, ConstantScoreQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_term", SpanTermQueryBuilder::new, SpanTermQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_not", SpanNotQueryBuilder::new, SpanNotQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_within", SpanWithinQueryBuilder::new, SpanWithinQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_containing", SpanContainingQueryBuilder::new, SpanContainingQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("field_masking_span", FieldMaskingSpanQueryBuilder::new, FieldMaskingSpanQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_first", SpanFirstQueryBuilder::new, SpanFirstQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_near", SpanNearQueryBuilder::new, SpanNearQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_gap", SpanGapQueryBuilder::new, SpanGapQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_or", SpanOrQueryBuilder::new, SpanOrQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("more_like_this", MoreLikeThisQueryBuilder::new, MoreLikeThisQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("wrapper", WrapperQueryBuilder::new, WrapperQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("common", CommonTermsQueryBuilder::new, CommonTermsQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("span_multi", SpanMultiTermQueryBuilder::new, SpanMultiTermQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("function_score", FunctionScoreQueryBuilder::new, FunctionScoreQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("simple_query_string", SimpleQueryStringBuilder::new, SimpleQueryStringBuilder::fromXContent));
this.registerQuery(new QuerySpec("type", TypeQueryBuilder::new, TypeQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("script", ScriptQueryBuilder::new, ScriptQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("geo_distance", GeoDistanceQueryBuilder::new, GeoDistanceQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("geo_bounding_box", GeoBoundingBoxQueryBuilder::new, GeoBoundingBoxQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("geo_polygon", GeoPolygonQueryBuilder::new, GeoPolygonQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("exists", ExistsQueryBuilder::new, ExistsQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("match_none", MatchNoneQueryBuilder::new, MatchNoneQueryBuilder::fromXContent));
this.registerQuery(new QuerySpec("terms_set", TermsSetQueryBuilder::new, TermsSetQueryBuilder::fromXContent));
if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
this.registerQuery(new QuerySpec("geo_shape", GeoShapeQueryBuilder::new, GeoShapeQueryBuilder::fromXContent));
}

this.registerFromPlugin(plugins, SearchPlugin::getQueries, this::registerQuery);
}

要回复问题请先登录注册