Skip to content

Commit fd037bd

Browse files
authored
retain the scores of portions of an ES|QL query, via a score function (elastic#127551)
1 parent 7139aa1 commit fd037bd

File tree

19 files changed

+988
-4
lines changed

19 files changed

+988
-4
lines changed

docs/reference/query-languages/esql/_snippets/functions/description/score.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/examples/score.md

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/score.md

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/parameters/score.md

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/score.md

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/images/functions/score.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/reference/query-languages/esql/kibana/definition/functions/score.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/docs/functions/score.md

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
###############################################
2+
# Tests for Score function
3+
#
4+
5+
scoreSingle
6+
required_capability: metadata_score
7+
required_capability: score_function
8+
required_capability: match_function
9+
10+
// tag::score-function[]
11+
FROM books METADATA _score
12+
| WHERE match(title, "Return") AND match(author, "Tolkien")
13+
| EVAL first_score = score(match(title, "Return"))
14+
// end::score-function[]
15+
| KEEP book_no, title, _score, first_score
16+
| SORT book_no
17+
| LIMIT 5
18+
;
19+
20+
// tag::score-single-result[]
21+
book_no:keyword | title:text | _score:double | first_score:double
22+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 3.1309072971343994 | 1.9245924949645996
23+
7350 | Return of the Shadow | 4.8434343338012695 | 3.5432329177856445
24+
// end::score-single-result[]
25+
;
26+
27+
scoreSingleNoMetadata
28+
required_capability: score_function
29+
required_capability: match_function
30+
31+
FROM books
32+
| WHERE match(title, "Return") AND match(author, "Tolkien")
33+
| EVAL first_score = score(match(title, "Return"))
34+
| KEEP book_no, title, first_score
35+
| SORT book_no
36+
| LIMIT 5
37+
;
38+
39+
book_no:keyword | title:text | first_score:double
40+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 1.9245924949645996
41+
7350 | Return of the Shadow | 3.5432329177856445
42+
;
43+
44+
scoreAfterEval
45+
required_capability: score_function
46+
required_capability: metadata_score
47+
required_capability: match_function
48+
49+
FROM books METADATA _score
50+
| EVAL stars = to_long(ratings / 2.0)
51+
| EVAL s1 = score(match(author, "William"))
52+
| WHERE match(author, "Faulkner")
53+
| SORT book_no
54+
| KEEP book_no, author, stars, s1
55+
| limit 5;
56+
57+
book_no:keyword | author:text | stars:long | s1:double
58+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott] | 3 | 0.0
59+
2713 | William Faulkner | 2 | 1.9043500423431396
60+
2847 | Colleen Faulkner | 3 | 0.0
61+
2883 | William Faulkner | 2 | 1.9043500423431396
62+
3293 | Danny Faulkner | 2 | 0.0
63+
;
64+
65+
scoreMatchWithFilterConjunction
66+
required_capability: score_function
67+
required_capability: match_function
68+
69+
FROM books
70+
| WHERE match(title, "Return") AND match(author, "Tolkien")
71+
| EVAL s1 = score(match(title, "Rings") and ratings > 4.6)
72+
| KEEP book_no, title, s1
73+
| SORT book_no
74+
| LIMIT 5;
75+
76+
book_no:keyword | title:text | s1:double
77+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 1.9245924949645996
78+
7350 | Return of the Shadow | 0.0
79+
;
80+
81+
scoreMatchWithDisjunction
82+
required_capability: score_function
83+
required_capability: match_function
84+
85+
FROM books
86+
| WHERE match(title, "Return") AND match(author, "Tolkien")
87+
| EVAL s1 = score(match(title, "Rings") or match(title, "Shadow"))
88+
| KEEP book_no, title, s1
89+
| SORT book_no
90+
| LIMIT 5;
91+
92+
book_no:keyword | title:text | s1:double
93+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 1.9245924949645996
94+
7350 | Return of the Shadow | 3.5432329177856445
95+
;
96+
97+
scoreMatchWithDisjunctionAndFilter
98+
required_capability: score_function
99+
required_capability: match_function
100+
101+
FROM books
102+
| WHERE match(title, "Return") AND match(author, "Tolkien")
103+
| EVAL s1 = score(match(title, "Rings") or match(title, "Shadow") and ratings > 4.6)
104+
| KEEP book_no, title, s1
105+
| SORT book_no
106+
| LIMIT 5;
107+
108+
book_no:keyword | title:text | s1:double
109+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 1.9245924949645996
110+
7350 | Return of the Shadow | 3.5432329177856445
111+
;
112+
113+
scoreMatchDisjunctionNonPushable
114+
required_capability: score_function
115+
required_capability: match_function
116+
117+
FROM books
118+
| WHERE match(title, "Return") AND match(author, "Tolkien")
119+
| EVAL s1 = score(match(title, "Rings") or ratings > 4.6)
120+
| KEEP book_no, title, s1
121+
| SORT book_no
122+
| LIMIT 5;
123+
124+
book_no:keyword | title:text | s1:double
125+
2714 | Return of the King Being the Third Part of The Lord of the Rings | 1.9245924949645996
126+
7350 | Return of the Shadow | 0.0
127+
;

0 commit comments

Comments
 (0)