custom-score-query.asciidoc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. [[query-dsl-custom-score-query]]
  2. === Custom Score Query
  3. deprecated[0.90.4,Replaced by <<query-dsl-function-score-query>>]
  4. `custom_score` query allows to wrap another query and customize the
  5. scoring of it optionally with a computation derived from other field
  6. values in the doc (numeric ones) using
  7. <<modules-scripting,script expression>>. Here is
  8. a simple sample:
  9. [source,js]
  10. --------------------------------------------------
  11. "custom_score" : {
  12. "query" : {
  13. ....
  14. },
  15. "script" : "_score * doc['my_numeric_field'].value"
  16. }
  17. --------------------------------------------------
  18. On top of the different scripting field values and expression, the
  19. `_score` script parameter can be used to retrieve the score based on the
  20. wrapped query.
  21. [float]
  22. ==== Script Parameters
  23. Scripts are cached for faster execution. If the script has parameters
  24. that it needs to take into account, it is preferable to use the same
  25. script, and provide parameters to it:
  26. [source,js]
  27. --------------------------------------------------
  28. "custom_score" : {
  29. "query" : {
  30. ....
  31. },
  32. "params" : {
  33. "param1" : 2,
  34. "param2" : 3.1
  35. },
  36. "script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)"
  37. }
  38. --------------------------------------------------