Elastic 8.1.1 - 无法实例化 FunctionScore,build() 受保护
Elastic 8.1.1 - Cannot instantiate FunctionScore, build() protected
我正在尝试从 elasticsearch 6.5.4 -> 8.1.1 迁移一些弹性功能,特别是 functionScoreQuery:
private SearchRequest buildRequest(String query) {
SearchRequest searchRequest = new SearchRequest(INDEX_ALIAS);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.functionScoreQuery(
getQuery(),
getFilterFunctions())
);
searchRequest.source(sourceBuilder);
return searchRequest;
}
private FilterFunctionBuilder[] getFilterFunctions() {
return new FilterFunctionBuilder[] {
boostFunction(termQuery("Term1", "Value1").boost(2.0f)),
boostFunction(termQuery("Term2", "Value2").boost(1.5f)),
};
}
private FunctionScoreQueryBuilder.FilterFunctionBuilder boostFunction(QueryBuilder query{
return new FilterFunctionBuilder(query, weightFactorFunction(1.0f));
}
我不知道如何使用新的 java api 来做到这一点。我正在尝试这样的事情:
private SearchRequest buildRequest(String query, int numberOfResults) {
return new SearchRequest.Builder()
.index(INDEX_ALIAS)
.query(buildQuery(query))
.build();
}
private Query buildQuery(String queryWithoutDots) {
return new Query.Builder()
.functionScore(f -> f
.query(getQueries())
.functions(getFilterFunctions())
)
.build();
}
private List<FunctionScore> getFilterFunctions() {
return List.of(
new FunctionScore.Builder()
.filter(new Query.Builder()
.term(t ->
t.queryName("Term1")
.value("Value1")
.boost(2.0f))
.build())
**.build(),**
new FunctionScore.Builder()
.filter(new Query.Builder()
.term(t ->
t.queryName("Term2")
.value("Value2")
.boost(1.5f))
.build())
**.build(),**
}
但是无法将 FunctionScore 实例化为
'build()' has protected access in
'co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore
这是一个错误吗?我应该考虑其他方法吗?
我明白了。例如,我需要使用修饰符:linear
new FunctionScore.Builder()
.linear(
l -> l.filter(
f -> f.term(
t -> t.queryName("Term1")
.value("Value1")
.boost(2.0f)
)
)
)
.build()
我正在尝试从 elasticsearch 6.5.4 -> 8.1.1 迁移一些弹性功能,特别是 functionScoreQuery:
private SearchRequest buildRequest(String query) {
SearchRequest searchRequest = new SearchRequest(INDEX_ALIAS);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.functionScoreQuery(
getQuery(),
getFilterFunctions())
);
searchRequest.source(sourceBuilder);
return searchRequest;
}
private FilterFunctionBuilder[] getFilterFunctions() {
return new FilterFunctionBuilder[] {
boostFunction(termQuery("Term1", "Value1").boost(2.0f)),
boostFunction(termQuery("Term2", "Value2").boost(1.5f)),
};
}
private FunctionScoreQueryBuilder.FilterFunctionBuilder boostFunction(QueryBuilder query{
return new FilterFunctionBuilder(query, weightFactorFunction(1.0f));
}
我不知道如何使用新的 java api 来做到这一点。我正在尝试这样的事情:
private SearchRequest buildRequest(String query, int numberOfResults) {
return new SearchRequest.Builder()
.index(INDEX_ALIAS)
.query(buildQuery(query))
.build();
}
private Query buildQuery(String queryWithoutDots) {
return new Query.Builder()
.functionScore(f -> f
.query(getQueries())
.functions(getFilterFunctions())
)
.build();
}
private List<FunctionScore> getFilterFunctions() {
return List.of(
new FunctionScore.Builder()
.filter(new Query.Builder()
.term(t ->
t.queryName("Term1")
.value("Value1")
.boost(2.0f))
.build())
**.build(),**
new FunctionScore.Builder()
.filter(new Query.Builder()
.term(t ->
t.queryName("Term2")
.value("Value2")
.boost(1.5f))
.build())
**.build(),**
}
但是无法将 FunctionScore 实例化为
'build()' has protected access in 'co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore
这是一个错误吗?我应该考虑其他方法吗?
我明白了。例如,我需要使用修饰符:linear
new FunctionScore.Builder()
.linear(
l -> l.filter(
f -> f.term(
t -> t.queryName("Term1")
.value("Value1")
.boost(2.0f)
)
)
)
.build()