I'm using the Java API (v 2.3.1) to run a custom scoring script as part of a query.
However, I've noticed that the scoring script is not applied unless I use a deprecated part of the API.
ie: This:
BoolQueryBuilder bool = QueryBuilders.boolQuery().minimumNumberShouldMatch(6);
... add bool limiters here via bool.should(...) ...
Map<String, Object> params = new HashMap<>();
... add script parameters here ...
QueryBuilder query = QueryBuilders.functionScoreQuery(bool).setMinScore(12.0f).add(ScoreFunctionBuilders.scriptFunction(new Script("hamming_distance", ScriptService.ScriptType.INLINE, "native", params)))
...execute query here ...
Produces this query json:
{
"function_score" : {
"query" : {
"bool" : {
"should" : [ ...bool limiters here... ],
"minimum_should_match" : "6"
}
},
"functions" : [ {
"script_score" : {
"script" : {
"inline" : "hamming_distance",
"lang" : "native",
"params" : {
...script params here...
}
}
}
} ],
"min_score" : 12.0
}
}
and the scoring script is not applied.
Whereas this:
BoolQueryBuilder bool = QueryBuilders.boolQuery().minimumNumberShouldMatch(6);
... add bool limiters here via bool.should(...) ...
Map<String, Object> params = new HashMap<>();
... add script parameters here ...
QueryBuilder filter = QueryBuilders.filteredQuery(null, bool); // This is deprecated
QueryBuilder query = QueryBuilders.functionScoreQuery(filter).setMinScore(12.0f).add(ScoreFunctionBuilders.scriptFunction(new Script("hamming_distance", ScriptService.ScriptType.INLINE, "native", params)))
...execute query here ...
produces this query json:
{
"function_score" : {
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"should" : [ ...bool limiters here... ],
"minimum_should_match" : "6"
}
}
}
},
"functions" : [ {
"script_score" : {
"script" : {
"inline" : "hamming_distance",
"lang" : "native",
"params" : {
...script params here...
}
}
}
} ],
"min_score" : 12.0
}
}
and the scoring script is correctly applied.
Am I doing this right?
Thanks for your time!