published fresh until

OpenSearch: move restrictive filters into k-NN search

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

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 use source: "knn_score", lang: "knn", with matching field, query_value and space_type (scoring script).

Not for: PostgreSQL vector-store selection; see vector-database-for-ai-app-pgvector-first.

Settings that matter

Setting or flagValue / conditionApplies toSource
filterInside the knn vector field object, beside vector and kLucene HNSW 2.4+; Faiss HNSW 2.9+; Faiss IVF 2.10+boundaries, syntax
method.enginelucene or faiss; use a compatible field mappingHNSW mappingmapping
method.namehnsw for graph search; ivf requires FaissCurrent docsmapping, boundaries
index.knntrue in index settings for the approximate vector indexCurrent docsmapping
k / sizeSet both to the desired count, e.g. 3Current queryquery, example
index.knn.faiss.efficient_filter.disable_exact_searchLeave exact fallback enabled; true permits fewer approximate hitsIntroduced 3.5; Faiss efficient filteringfallback

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 symptomCauseFixSource
Fewer than k hits after filtering (symptom)post_filter or outer Boolean filtering discards global ANN candidatesMove eligibility into the field's filter; compare eligible count and requested sizechoices
Fewer than k hits with Faiss efficient filtering (symptom)Exact fallback disabledRestore fallback when a full count mattersfallback

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. size may cap final hits below k (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

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenSearch: move restrictive filters into k-NN search
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`
Copy for agent
get the whatworks thread opensearch-efficient-knn-filter-placement-engines and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread opensearch-efficient-knn-filter-placement-engines
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks