-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add support for scored named queries (#11626) Opensearch already support labelling the queries, that returns as a list in the returned results, of which query it matched. However one of the use case while doing hybrid search with query text and dense vector is to determine individual scores for each query type. This is very useful in further analysis and building offline model to generate better weights for ranking score. Hence adding this feature that sends the client to add the score for each matched query. --------- Signed-off-by: Dharin Shah <[email protected]> Signed-off-by: Dharin Shah <[email protected]> Co-authored-by: Dharin Shah <[email protected]> (cherry picked from commit 52b27f4) Signed-off-by: Andrew Ross <[email protected]> * Update version checks Signed-off-by: Andrew Ross <[email protected]> * Update test version guard Co-authored-by: Andriy Redko <[email protected]> Signed-off-by: Andrew Ross <[email protected]> --------- Signed-off-by: Dharin Shah <[email protected]> Signed-off-by: Dharin Shah <[email protected]> Signed-off-by: Andrew Ross <[email protected]> Co-authored-by: Dharin Shah <[email protected]> Co-authored-by: Dharin Shah <[email protected]> Co-authored-by: Andriy Redko <[email protected]>
- Loading branch information
1 parent
44f1417
commit 4e03b28
Showing
23 changed files
with
672 additions
and
105 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
103 changes: 103 additions & 0 deletions
103
rest-api-spec/src/main/resources/rest-api-spec/test/search/350_matched_queries.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,103 @@ | ||
setup: | ||
- skip: | ||
version: " - 2.12.99" | ||
reason: "implemented for versions post 2.12.99" | ||
|
||
--- | ||
"matched queries": | ||
- do: | ||
indices.create: | ||
index: test | ||
|
||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- '{ "index" : { "_index" : "test_1", "_id" : "1" } }' | ||
- '{"field" : 1 }' | ||
- '{ "index" : { "_index" : "test_1", "_id" : "2" } }' | ||
- '{"field" : [1, 2] }' | ||
|
||
- do: | ||
search: | ||
index: test_1 | ||
body: | ||
query: | ||
bool: { | ||
should: [ | ||
{ | ||
match: { | ||
field: { | ||
query: 1, | ||
_name: match_field_1 | ||
} | ||
} | ||
}, | ||
{ | ||
match: { | ||
field: { | ||
query: 2, | ||
_name: match_field_2, | ||
boost: 10 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
- match: {hits.total.value: 2} | ||
- length: {hits.hits.0.matched_queries: 2} | ||
- match: {hits.hits.0.matched_queries: [ "match_field_1", "match_field_2" ]} | ||
- length: {hits.hits.1.matched_queries: 1} | ||
- match: {hits.hits.1.matched_queries: [ "match_field_1" ]} | ||
|
||
--- | ||
|
||
"matched queries with scores": | ||
- do: | ||
indices.create: | ||
index: test | ||
|
||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- '{ "index" : { "_index" : "test_1", "_id" : "1" } }' | ||
- '{"field" : 1 }' | ||
- '{ "index" : { "_index" : "test_1", "_id" : "2" } }' | ||
- '{"field" : [1, 2] }' | ||
|
||
- do: | ||
search: | ||
include_named_queries_score: true | ||
index: test_1 | ||
body: | ||
query: | ||
bool: { | ||
should: [ | ||
{ | ||
match: { | ||
field: { | ||
query: 1, | ||
_name: match_field_1 | ||
} | ||
} | ||
}, | ||
{ | ||
match: { | ||
field: { | ||
query: 2, | ||
_name: match_field_2, | ||
boost: 10 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
- match: { hits.total.value: 2 } | ||
- length: { hits.hits.0.matched_queries: 2 } | ||
- match: { hits.hits.0.matched_queries.match_field_1: 1 } | ||
- match: { hits.hits.0.matched_queries.match_field_2: 10 } | ||
- length: { hits.hits.1.matched_queries: 1 } | ||
- match: { hits.hits.1.matched_queries.match_field_1: 1 } |
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.