2015-06-24 17:27:19 -04:00
|
|
|
[[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]
|
|
|
|
--------------------------------------------------
|
2015-10-19 06:17:45 -04:00
|
|
|
FilterFunctionBuilder[] functions = {
|
|
|
|
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
|
|
|
|
matchQuery("name", "kimchy"), <1>
|
|
|
|
randomFunction("ABCDEF")), <2>
|
|
|
|
new FunctionScoreQueryBuilder.FilterFunctionBuilder(
|
|
|
|
exponentialDecayFunction("age", 0L, 1L)) <3>
|
|
|
|
};
|
2015-06-24 17:27:19 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
<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
|
|
|
|
|