"The heap is empty" error on KNN search

  1. Yes, there is a difference, doing a filter outside KNN is an OR combination. Either docs match the filter, or KNN or both. Note, the filtered documents are unscored, but they may be scored by the KNN query.
  2. It is not a post-filter, but it is an AND combination.
  3. Yes, this is how you should do it.

Something like this would be an OR combination with a filter & KNN.

{
       "query": {
           "bool": {
                "must_not": { "term": {"some_field": 14642652} },
                "filter": {"term": {"some_field2": true}}
           }
        },
	"knn": {
		"field": "photo_vector",
		"k": 5,
		"num_candidates": 5,
		"query_vector": [
			...
		]
	}
}

To get the full stack trace to fully debug your original issue, I have confirmed the query parameters allow_partial_search_results=false&error_trace=true are what you need. If you want to dig into that further.

1 Like