FunctionScoreQueryBuilder.add() removed?

I'm trying to implement function_score in Java code. This


is exactly what I'm looking for.
This page also has similar examples: https://www.programcreek.com/java-api-examples/index.php?api=org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder

Problem is, apparently FunctionScoreQueryBuilder.add() has been removed since ElasticSearch 5.x. What should be used instead? Any code examples?

This may help:

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-compound-queries.html#java-query-dsl-function-score-query

Thanks dadoonet. That's very helpful.

Add more example here that works for me:
For functions
"functions":[
{
"filter":{
"match":{
"my-data-field":{
"query":"field-value"
}
}
},
"weight":3.0
},
{
"gauss":{
"my-date-field":{
"scale":"360d",
"offset":"90d",
"decay":0.5
}
}
}
]
The Java code:
List functionBuilders = new ArrayList<>();
MatchQueryBuilder matchQryBdlr = QueryBuilders.matchQuery("my-data-field", "field-value");
WeightBuilder weightBdlr = ScoreFunctionBuilders.weightFactorFunction(3.0);
functionBuilders.add(new FilterFunctionBuilder(matchQryBdlr, weightBdlr));

GaussDecayFunctionBuilder gaussBuilder = new GaussDecayFunctionBuilder("my-date-field", null, "360d", "90d", 0.5);
functionBuilders.add(new FilterFunctionBuilder(gaussBuilder));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.