1
0

function-score-query.asciidoc 892 B

123456789101112131415161718192021222324252627
  1. [[java-query-dsl-function-score-query]]
  2. ==== Function Score Query
  3. See {ref}/query-dsl-function-score-query.html[Function Score Query].
  4. To use `ScoreFunctionBuilders` just import them in your class:
  5. [source,java]
  6. --------------------------------------------------
  7. import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.*;
  8. --------------------------------------------------
  9. [source,java]
  10. --------------------------------------------------
  11. QueryBuilder qb = functionScoreQuery()
  12. .add(
  13. matchQuery("name", "kimchy"), <1>
  14. randomFunction("ABCDEF") <2>
  15. )
  16. .add(
  17. exponentialDecayFunction("age", 0L, 1L) <3>
  18. );
  19. --------------------------------------------------
  20. <1> Add a first function based on a query
  21. <2> And randomize the score based on a given seed
  22. <3> Add another function based on the age field