OpenSearch/docs/java-api/query-dsl/function-score-query.asciidoc

27 lines
1019 B
Plaintext

[[java-query-dsl-function-score-query]]
==== Function Score Query
See {ref}/query-dsl-function-score-query.html[Function Score Query].
To use `ScoreFunctionBuilders` just import them in your class:
[source,java]
--------------------------------------------------
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.*;
--------------------------------------------------
[source,java]
--------------------------------------------------
FilterFunctionBuilder[] functions = {
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
matchQuery("name", "kimchy"), <1>
randomFunction("ABCDEF")), <2>
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
exponentialDecayFunction("age", 0L, 1L)) <3>
};
--------------------------------------------------
<1> Add a first function based on a query
<2> And randomize the score based on a given seed
<3> Add another function based on the age field