sliu
September 26, 2017, 1:35am
1
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?
dadoonet
(David Pilato)
September 26, 2017, 1:50am
2
sliu
September 28, 2017, 1:08pm
3
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));
system
(system)
Closed
October 26, 2017, 1:09pm
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.