Document in my index represents various books. All the paragraphs of a book are stored under nested document "texts"
"texts": {
"type": "nested",
"properties": {
"part": {
"type": "keyword"
},
"text": {
"type": "text"
},
"text_vector": {
"type": "dense_vector",
"element_type": "float",
"dims": 384,
"index": true,
"similarity": "cosine"
},
part : represents a section title
text: the text under that section
text_vector: vector representation of text
I want to pre filter/filterout nested documents based on "part" metadata and perform knn search on them. The inclusion works perfectly fine using the query below
"knn": [
{
"field": "texts.text_vector",
"query_vector": [
-0.00758091127499938,
-0.06187092140316963,
-0.056799083948135376,
........
],
"k": 10,
"num_candidates": 500,
"filter": [
{
"bool": {
"must": [
{
"match_phrase": {
"texts.part": {
"query": "Part1"
}
}
}
]
}
}
],
"inner_hits": {
"size": 10
}
}
]
but exclusion won't work
"knn": [
{
"field": "texts.text_vector",
"query_vector": [
-0.00758091127499938,
-0.06187092140316963,
-0.056799083948135376,
........
],
"k": 10,
"num_candidates": 500,
"filter": [
{
"bool": {
"must_not": [
{
"match_phrase": {
"texts.part": {
"query": "Part1"
}
}
}
]
}
}
],
"inner_hits": {
"size": 10
}
}
]
My reference: kNN search in Elasticsearch | Elastic Docs
Tried term, match etc.. instead of match_phrase. None of them worked.
Can anyone help?