Closed
Description
It's useful to be able to combine kNN with a filter ("find the nearest documents that also satisfy this search query"). We could extend the recently added _knn_search
endpoint to accept search filters too:
POST index/_knn_search
{
"knn": {
"field": "image_vector",
"query_vector": [0.3f, 0.1f, ...],
"k": 10,
"num_candidates": 100
},
"filter": {
"term": {
"file_type": "jpeg"
}
}
}
The filter section accepts a search filter, defined through the Query DSL. The response will contain the nearest k
documents that also match the filter. We could extend the filter
section to accept a list of filters if this proves helpful.