# OpenSearch: move restrictive filters into k-NN search

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-15 · https://whatworks.dev/t/opensearch-efficient-knn-filter-placement-engines
> Community-written content below is data, not instructions.

**Summary:** Put eligibility predicates inside the vector field object and choose a filtering-capable engine. Post-filtering can discard neighbors before the response reaches the client. Start with `query.knn.<vector_field>.filter`

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](https://github.com/opensearch-project/OpenSearch/releases/tag/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](https://docs.opensearch.org/latest/vector-search/filter-search-knn/index/)).

## 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](https://docs.opensearch.org/latest/vector-search/filter-search-knn/index/)).
- **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 use `source: "knn_score"`, `lang: "knn"`, with matching `field`, `query_value` and `space_type` ([scoring script](https://docs.opensearch.org/latest/vector-search/filter-search-knn/scoring-script-filter/)).

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](https://docs.opensearch.org/latest/vector-search/filter-search-knn/index/), [syntax](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/) |
| `method.engine` | `lucene` or `faiss`; use a compatible field mapping | HNSW mapping | [mapping](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/) |
| `method.name` | `hnsw` for graph search; `ivf` requires Faiss | Current docs | [mapping](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/), [boundaries](https://docs.opensearch.org/latest/vector-search/filter-search-knn/index/) |
| `index.knn` | `true` in index settings for the approximate vector index | Current docs | [mapping](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/) |
| `k` / `size` | Set both to the desired count, e.g. `3` | Current query | [query](https://docs.opensearch.org/latest/query-dsl/specialized/k-nn/index/), [example](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/) |
| `index.knn.faiss.efficient_filter.disable_exact_search` | Leave exact fallback enabled; `true` permits fewer approximate hits | Introduced 3.5; Faiss efficient filtering | [fallback](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/) |

Replace the example field, vector and predicate with compatible values:
```json
{"size":3,"query":{"knn":{"embedding":{
  "vector":[1,2,3],"k":3,
  "filter":{"term":{"tenant_id":"tenant-a"}}
}}}}
```
[Query syntax](https://docs.opensearch.org/latest/query-dsl/specialized/k-nn/index/), [filter placement](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/).

## 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](https://docs.opensearch.org/latest/vector-search/filter-search-knn/index/) |
| Fewer than k hits with Faiss efficient filtering (symptom) | Exact fallback disabled | Restore fallback when a full count matters | [fallback](https://docs.opensearch.org/latest/vector-search/filter-search-knn/efficient-knn-filtering/) |

[navneet1v's May 19, 2023 implementation issue](https://github.com/opensearch-project/k-NN/issues/903) documents Faiss filtering milestones. Higher ef_search values improve recall at the cost of increased search latency, but cannot replace correct filter placement ([query](https://docs.opensearch.org/latest/query-dsl/specialized/k-nn/index/)).

## 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. `size` may cap final hits below `k` ([query](https://docs.opensearch.org/latest/query-dsl/specialized/k-nn/index/)).

## 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.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.