Suppose my index has:
- A vector field called "text_encoded"
- A field called "field1", that can contain one or more of the following classes: "A", "B", "C" as list (ex. "field1" : ["A"], or "field1" : ["A", "C"])
I would like to write an OpenSearch query that can:
- select the samples with field1 classes containing either "A" OR "C"
- return similarity scores only
If I use the "should" instruction, it returns relevance scores instead.
The below query enables you to achieve this. Note that it uses Exact kNN with Scoring Script, as opposed to approximate kNN.
First, the
script_score.query
clause fetches a subset of documents wherefield1
is either "A" or "B". Then, thescript_score.script
clause performs kNN on the aforementioned set.Good luck!