[BUG] Hybrid query different total.value on different sizes on 3.x versions
Describe the bug
When wrapping simple match clause into hybrid query with low size, hits.total.value is different than in plain match query.
In example I have test index with simple text field, match by word returns hits.total.value 933 with any size param
If I wrap it into hybrid.queries and call it with size lower than 737, hits.total.value = 761
If I ran same hybrid query with size 737 or higher, total.value is correct (933).
Also first three documents in hybrid query in hits are the same but with different scores
Related component
Search
To Reproduce
- Create OpenSearch 3.8.0 instance
podman run -d \
--name opensearch-3-8 \
-p 9203:9200 \
-p 9603:9600 \
-e "discovery.type=single-node" \
-e "DISABLE_SECURITY_PLUGIN=true" \
docker.io/opensearchproject/opensearch:3.8.0- Run this script to create lorem_idx index with 5000 documents(
python3 create_lorem_idx.py --host localhost --port 9203) create_lorem_idx.py - Run this query to get correct
hits.total.value(933 for me)
curl --request POST \
--url http://localhost:9203/lorem_idx/_search \
--H 'Content-Type: application/json' \
--d '
{
"from": 0,
"query": {
"match": {
"text": "dolor"
}
},
"size": 10,
"_source": false
}'- Run this query to see lower
hits.total.value(737 for me)
curl --request POST \
--url http://localhost:9203/lorem_idx/_search \
--H 'Content-Type: application/json' \
--d '
{
"from": 0,
"query": {
"hybrid": {
"queries": [
{
"match": {
"text": "dolor"
}
}
]
}
},
"size": 10,
"_source": false
}'- Run query with higher size, to see correct
hits.total.value(933 for me)
curl --request POST \
--url http://localhost:9203/lorem_idx/_search \
--H 'Content-Type: application/json' \
--d '
{
"from": 0,
"query": {
"hybrid": {
"queries": [
{
"match": {
"text": "dolor"
}
}
]
}
},
"size": 10000,
"_source": false
}'hits.total.value from second query (step 4) is different from first and third query (step 3 and 5).
Expected behavior
hits.total.valueshould be the same for any size for hybrid query.- All
hits.total.valuefrom each of these queries should be equal. - First document should not be duplicated in hybrid query response
Additional Details
Screenshots
First response (from step 3)
Second response (from step 4)
Third response (from step 5)
Host/Environment (please complete the following information):
- OS: [MacOS Tahoe 26.3.1, Amazon OpenSearch Service in production ]
- Versions [3.5, 3.6, 3.7, 3.8]
Additional context I found this issue when upgraded from 2.19 to 3.5 version in Amazon OpenSearch Service. Reproduced it locally on 3.5, 3.6, 3.7 and 3.8 versions I know that you are not supposed to run hybrid query with one subquery inside, but I had it with two queries (knn + multimatch) in production. Narrowed it down to this simple example
Source: opensearch-project/OpenSearch