I'm trying to build the following query in elasticsearch-java
library.
{
"from": 0,
"size": 10,
"query": {
"function_score": {
"functions": [
{
"filter": {
"term": {
"cat": "val1"
}
},
"weight": 40
},
{
"filter": {
"term": {
"bat": "val2"
}
},
"weight": 30
}
],
"query": {
"bool": {
"must": [....]
}
}
}
}
I'm not able to create Function Cores. I tried following.
FunctionScoreQuery.Builder functionScoreBuilder = new FunctionScoreQuery.Builder();
functionScoreBuilder.functions(function -> {
function.filter(filt-> {
filt.term(term -> {
term.field("cat").field("val1");
return term;
});
return filt;
});
return function; // COMPILATION ERROR - Type mismatch: cannot convert from FunctionScore.Builder to
ObjectBuilder<FunctionScore>
});
POM
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.17.2</version>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>7.17.2</version>
</dependency>
Usually in the functions whatever the input could be output. But filter level, I see none of the functions returning desired object.