What this thread does
Do first: move the predicate from post_filter into query.knn.<vector_field>.filter, after checking that the field uses lucene or faiss.
Short answer
As of November 2026, use OpenSearch 3.9.0 and current vector-search docs. Post-filtering is performed after the vector search; this approach may return significantly fewer than k results for a restrictive filter. Efficient filtering participates in search (filter choices).
Choose / don't choose
- Efficient filtering: choose for approximate retrieval over substantial eligible subsets; don't leave eligibility solely in an outer Boolean filter or
post_filter(choices). - Exact scoring: choose when a small eligible subset makes brute-force scoring affordable or exact ranking matters; don't assume it scales to large subsets. Put the predicate in
script_score.query.bool.filter, then usesource: "knn_score",lang: "knn", with matchingfield,query_valueandspace_type(scoring script).
Not for: PostgreSQL vector-store selection; see vector-database-for-ai-app-pgvector-first.
Settings that matter
| Setting or flag | Value / condition | Applies to | Source |
|---|---|---|---|
filter | Inside the knn vector field object, beside vector and k | Lucene HNSW 2.4+; Faiss HNSW 2.9+; Faiss IVF 2.10+ | boundaries, syntax |
method.engine | lucene or faiss; use a compatible field mapping | HNSW mapping | mapping |
method.name | hnsw for graph search; ivf requires Faiss | Current docs | mapping, boundaries |
index.knn | true in index settings for the approximate vector index | Current docs | mapping |
k / size | Set both to the desired count, e.g. 3 | Current query | query, example |
index.knn.faiss.efficient_filter.disable_exact_search | Leave exact fallback enabled; true permits fewer approximate hits | Introduced 3.5; Faiss efficient filtering | fallback |
Replace the example field, vector and predicate with compatible values:
{"size":3,"query":{"knn":{"embedding":{
"vector":[1,2,3],"k":3,
"filter":{"term":{"tenant_id":"tenant-a"}}
}}}}
Query syntax, filter placement.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Fewer than k hits after filtering (symptom) | post_filter or outer Boolean filtering discards global ANN candidates | Move eligibility into the field's filter; compare eligible count and requested size | choices |
| Fewer than k hits with Faiss efficient filtering (symptom) | Exact fallback disabled | Restore fallback when a full count matters | fallback |
navneet1v's May 19, 2023 implementation issue documents Faiss filtering milestones. Higher ef_search values improve recall at the cost of increased search latency, but cannot replace correct filter placement (query).
Missing
- No universal selectivity/latency threshold chooses exact versus approximate search; compare both on the same eligible subset and distance metric.
- The filter overview also lists optional JVector while the core query table names Faiss/Lucene; this card uses the latter two.
- The linked source does not confirm: IVF requires separate setup.
sizemay cap final hits belowk(query).
Checked
2026-11-12; OpenSearch release, filtering overview, efficient mapping/query/fallback, scoring script, k-NN query and dated navneet1v issue read. No search cluster commands executed.
Started from a post by @OpenSearch, packaged by the editor. Original post