-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add randomScore function in script_score query (#40186)
To make script_score query to have the same features as function_score query, we need to add randomScore function. This function produces different random scores on different index shards. It is also able to produce random scores based on the internal Lucene Document Ids.
- Loading branch information
1 parent
65e0317
commit 459715d
Showing
8 changed files
with
301 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...-painless/src/test/resources/rest-api-spec/test/painless/85_script_score_random_score.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Integration tests for ScriptScoreQuery using Painless | ||
|
||
setup: | ||
- skip: | ||
version: " - 7.99.99" # correct to 7.09.99 after backporting to 7.1 | ||
reason: "random score function of script score was added in 7.1" | ||
|
||
--- | ||
"Random score function with _seq_no field": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 2 | ||
mappings: | ||
properties: | ||
f1: | ||
type: keyword | ||
|
||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v0"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v1"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v2"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v3"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v4"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v5"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v6"}' | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "randomScore(100, '_seq_no')" | ||
# stash ids to check for reproducibility of ranking | ||
- set: { hits.hits.0._id: id0 } | ||
- set: { hits.hits.1._id: id1 } | ||
- set: { hits.hits.2._id: id2 } | ||
- set: { hits.hits.3._id: id3 } | ||
- set: { hits.hits.4._id: id4 } | ||
- set: { hits.hits.5._id: id5 } | ||
- set: { hits.hits.6._id: id6 } | ||
|
||
# check that ranking is reproducible | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "randomScore(100, '_seq_no')" | ||
- match: { hits.hits.0._id: $id0 } | ||
- match: { hits.hits.1._id: $id1 } | ||
- match: { hits.hits.2._id: $id2 } | ||
- match: { hits.hits.3._id: $id3 } | ||
- match: { hits.hits.4._id: $id4 } | ||
- match: { hits.hits.5._id: $id5 } | ||
- match: { hits.hits.6._id: $id6 } | ||
|
||
--- | ||
"Random score function with internal doc Ids": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 1 | ||
mappings: | ||
properties: | ||
f1: | ||
type: keyword | ||
|
||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v0"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v1"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v2"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v3"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v4"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v5"}' | ||
- '{"index": {"_index": "test"}}' | ||
- '{"f1": "v6"}' | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "randomScore(100)" | ||
# stash ids to check for reproducibility of ranking | ||
- set: { hits.hits.0._id: id0 } | ||
- set: { hits.hits.1._id: id1 } | ||
- set: { hits.hits.2._id: id2 } | ||
- set: { hits.hits.3._id: id3 } | ||
- set: { hits.hits.4._id: id4 } | ||
- set: { hits.hits.5._id: id5 } | ||
- set: { hits.hits.6._id: id6 } | ||
|
||
# check that ranking is reproducible | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "randomScore(100)" | ||
- match: { hits.hits.0._id: $id0 } | ||
- match: { hits.hits.1._id: $id1 } | ||
- match: { hits.hits.2._id: $id2 } | ||
- match: { hits.hits.3._id: $id3 } | ||
- match: { hits.hits.4._id: $id4 } | ||
- match: { hits.hits.5._id: $id5 } | ||
- match: { hits.hits.6._id: $id6 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.