I’m using Python 3.9 and I’m able to do hybrid search (query and knn) on Elasticsearch index. I’m Also able to do simple count either query or knn. but when I try to do hybrid count (query and knn) it does not work. I don’t know what I’m doing wrong. Below are the different approach that I used.
<code> # Count documents matching a query
query = {
"query": {
"bool": {
"must": [
{
"match": {
"title": sentence
}
},
{
"knn": {
"field" : "titleVector",
"query_vector" : embedding_vector,
"similarity":1,
"k":7000,
"num_candidates":10000
}
}
]
}
}
}
response = es.count(
index="rktb_framework",
body = query
)
print(response)
</code>
<code> # Count documents matching a query
query = {
"query": {
"bool": {
"must": [
{
"match": {
"title": sentence
}
},
{
"knn": {
"field" : "titleVector",
"query_vector" : embedding_vector,
"similarity":1,
"k":7000,
"num_candidates":10000
}
}
]
}
}
}
response = es.count(
index="rktb_framework",
body = query
)
print(response)
</code>
# Count documents matching a query
query = {
"query": {
"bool": {
"must": [
{
"match": {
"title": sentence
}
},
{
"knn": {
"field" : "titleVector",
"query_vector" : embedding_vector,
"similarity":1,
"k":7000,
"num_candidates":10000
}
}
]
}
}
}
response = es.count(
index="rktb_framework",
body = query
)
print(response)