forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
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
To make script_score query to have the same features as function_score query, we need to add randomScore function. This function should be able to produce different random scores on different index shards. It also needs to be able to produce random scores based on the internal Lucene Document Ids. To achieve this three variables have been added to the score script context: - _doc for the internal Lucene doc id - _shard for the shard id - _indexName for the index name Closes elastic#31461
- Loading branch information
1 parent
31dd9c3
commit 4c7b596
Showing
8 changed files
with
177 additions
and
123 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
76 changes: 76 additions & 0 deletions
76
...-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,76 @@ | ||
# 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": | ||
- 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(String.valueOf(doc['_seq_no'].value), _index, _shard, 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(String.valueOf(doc['_seq_no'].value), _index, _shard, 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
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.