search.asciidoc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-search]]
  4. === Full-Text Search Functions
  5. beta[]
  6. Search functions should be used when performing full-text search, namely
  7. when the `MATCH` or `QUERY` predicates are being used.
  8. Outside a, so-called, search context, these functions will return default values
  9. such as `0` or `NULL`.
  10. [[sql-functions-search-score]]
  11. ==== `SCORE`
  12. .Synopsis:
  13. [source, sql]
  14. --------------------------------------------------
  15. SCORE()
  16. --------------------------------------------------
  17. *Input*: _none_
  18. *Output*: `double` numeric value
  19. .Description:
  20. Returns the {defguide}/relevance-intro.html[relevance] of a given input to the executed query.
  21. The higher score, the more relevant the data.
  22. NOTE: When doing multiple text queries in the `WHERE` clause then, their scores will be
  23. combined using the same rules as {es}'s
  24. <<query-dsl-bool-query,bool query>>.
  25. Typically `SCORE` is used for ordering the results of a query based on their relevance:
  26. ["source","sql",subs="attributes,callouts,macros"]
  27. ----
  28. include-tagged::{sql-specs}/docs.csv-spec[orderByScore]
  29. ----
  30. However, it is perfectly fine to return the score without sorting by it:
  31. ["source","sql",subs="attributes,callouts,macros"]
  32. ----
  33. include-tagged::{sql-specs}/docs.csv-spec[scoreWithMatch]
  34. ----