Filtering & Payload Indexing
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Every point’s payload is arbitrary JSON, but it is also a filterable schema: declaring a payload index on a field lets Qdrant narrow a search to the points matching a boolean condition tree before (and during) the vector comparison, instead of scanning payload values one by one.
The examples on this page use the six-product products catalog from
the running example, extended with the payload fields
below. Every output shown was produced by running the call against that data on Qdrant 1.20.
| id | Name | Payload (abridged) |
|---|---|---|
1 |
Studio headphones |
audio, price 249, rating 4.7, acme, in stock, tags |
2 |
Bluetooth speaker |
audio, price 89, rating 4.2, globex, in stock, tags |
3 |
Soundbar |
audio, price 399, rating 4.5, acme, out of stock, tags |
4 |
Mechanical keyboard |
computing, price 129, rating 4.6, initech, in stock, tag |
5 |
Ergonomic mouse |
computing, price 59, rating 4.1, initech, in stock, tag |
6 |
Espresso machine |
kitchen, price 320, rating 4.8, globex, out of stock, no tags, Paris |
Payload — introduced alongside the point itself on
Collections & Points — is a free-form JSON object: strings, numbers, booleans, arrays, and nested objects, stored and returned with every point. Filtering treats that same JSON as a queryable schema: any payload field can appear in a filter condition, indexed or not, though an unindexed field is checked with a full scan of the field’s stored values rather than a lookup structure. See Payload for the complete set of supported value types and payload operations (set, overwrite, delete individual keys).
Payload indexes
A payload index is created explicitly, per field, and per value type — Qdrant does not infer an index from the values it sees. Four field schema types cover the condition types below:
| Index type | What it accelerates |
|---|---|
|
Exact-match filtering on string values (and arrays of strings) — category codes, tags, status enums. |
|
Exact match and numeric range filtering on integer values. |
|
Location filtering with |
|
Full-text, word-level matching (tokenized, so a |
PUT /collections/products/index
{
"field_name": "category",
"field_schema": "keyword"
}
PUT /collections/products/index
{
"field_name": "price",
"field_schema": "integer"
}
PUT /collections/products/index
{
"field_name": "location",
"field_schema": "geo"
}
PUT /collections/products/index
{
"field_name": "description",
"field_schema": "text"
}
from qdrant_client.models import PayloadSchemaType
client.create_payload_index(
collection_name="products",
field_name="category",
field_schema=PayloadSchemaType.KEYWORD,
)
client.create_payload_index(
collection_name="products",
field_name="price",
field_schema=PayloadSchemaType.INTEGER,
)
Beyond the four types above, Qdrant also indexes float, bool, datetime and uuid fields. Creating the
indexes for the catalog and asking the collection what it has gives:
P = models.PayloadSchemaType
for field, schema in [("category", P.KEYWORD), ("price", P.INTEGER), ("rating", P.FLOAT),
("in_stock", P.BOOL), ("added", P.DATETIME), ("location", P.GEO)]:
client.create_payload_index("products", field, schema, wait=True)
client.create_payload_index("products", "name", models.TextIndexParams(
type="text", tokenizer=models.TokenizerType.WORD, lowercase=True, min_token_len=2), wait=True)
print({k: (v.data_type.value, v.points) for k, v in client.get_collection("products").payload_schema.items()})
# {'in_stock': ('bool', 6), 'price': ('integer', 6), 'rating': ('float', 6), 'added': ('datetime', 6),
# 'name': ('text', 6), 'category': ('keyword', 6), 'location': ('geo', 6)}
points counts how many points actually carry the field, which is a quick way to spot a field that most points
lack. The text index takes parameters: the word tokenizer splits on word boundaries, lowercase makes matching
case-insensitive, and min_token_len drops very short tokens. Other tokenizers (prefix, whitespace,
multilingual) trade precision for features such as autocomplete.
When an index is worth creating
Filtering works on any payload field, indexed or not. The index decides how fast and, for a few features, whether:
-
A filter on an unindexed field is evaluated by reading each candidate point’s payload. On six points that is instant (the unindexed
in_stockandtagsfilters below returned correct results before any index existed); on millions it dominates the query. -
order_byin scroll requires an integer, float or datetime index and fails otherwise. -
facetrequires an index on the faceted field; faceting the unindexedbrandfield fails withNo appropriate index for faceting: brand. -
An index adds memory (or disk) and slows ingestion slightly, so index the fields that appear in filters of frequent queries, not every field.
For multi-tenant collections where every query filters on one tenant field, a keyword index created with
is_tenant=True tells Qdrant to co-locate each tenant’s vectors, and an is_principal=True integer or datetime index
does the same for a field queries almost always range over. Both are optimizations of the same index mechanism, set
through the KeywordIndexParams and IntegerIndexParams objects.
Filter clauses
A filter is a tree of three boolean clauses, each holding a list of conditions:
| Clause | Semantics |
|---|---|
|
Every condition in the list has to match — logical AND. |
|
At least one condition in the list has to match — logical OR. |
|
No condition in the list may match — logical NOT, applied to the whole list. |
The three can be combined in one filter, and clauses can nest to build arbitrary boolean expressions. One
semantic trap deserves emphasis: in Qdrant a should list is a requirement, not a ranking preference. When a
filter has both must and should, a point must satisfy every must condition and at least one should
condition. On the catalog, a filter with must: price <= 300, should: brand is acme or globex and
must_not: in_stock is false returns only the headphones and the speaker (ids 1 and 2): the keyboard and mouse
are cheap and in stock but are neither acme nor globex, so the should clause rejects them. To rank rather than
exclude, use a score-boosting formula query or a second prefetch branch instead.
Because every clause can hold a nested Filter, any boolean expression is expressible. For example, "acme products or
anything under 60, but never out of stock" is a must holding two nested filters:
Filter(must=[
Filter(should=[FieldCondition(key="brand", match=MatchValue(value="acme")),
FieldCondition(key="price", range=Range(lt=60))]),
Filter(must_not=[FieldCondition(key="in_stock", match=MatchValue(value=False))]),
])
# scroll result: ids [1, 5] (the acme soundbar, id 3, is out of stock)
min_should generalizes OR and AND: it takes a list of conditions and a min_count, and a point passes when at
least min_count of them hold. With category = audio, in_stock = true and price < 100 and min_count=2, the
catalog yields ids 1, 2 and 5 (the soundbar satisfies only one condition). Each condition itself is one of a few condition types:
-
match — exact value equality against a
keywordorintegerfield (or "any of these values" viamatch.any). -
range — numeric or date bounds (
gt,gte,lt,lte) against aninteger/float/datetime field. -
geo —
geo_radius(points within a distance of a center) orgeo_bounding_box(points inside a lat/lon rectangle) against ageofield.
POST /collections/products/points/scroll
{
"filter": {
"must": [
{ "key": "category", "match": { "value": "audio" } },
{ "key": "price", "range": { "lte": 300 } }
],
"should": [
{ "key": "brand", "match": { "any": ["acme", "globex"] } }
],
"must_not": [
{ "key": "discontinued", "match": { "value": true } }
]
},
"limit": 10
}
A geo condition narrows to points whose location field falls inside a radius or a rectangle:
POST /collections/products/points/scroll
{
"filter": {
"must": [
{
"key": "location",
"geo_radius": {
"center": { "lon": 13.403, "lat": 52.520 },
"radius": 5000.0
}
}
]
},
"limit": 10
}
Running the geo example against the catalog returns the headphones, the soundbar and the mouse (ids 1, 3, 5),
the three Berlin products within 5 km of the center, while the Paris and London products fall outside.
geo_bounding_box takes top_left and bottom_right corners instead of a center and radius, for a
rectangular region rather than a circle. Full condition and clause reference:
Filtering.
The condition types beyond the three above are best seen side by side. Each row is a real filter run against the catalog, with the ids it matched:
| Intent | Condition (Python client) | Matches |
|---|---|---|
Exact boolean |
|
1, 2, 4, 5 |
Exclude values |
|
4, 5 |
Float range |
|
1, 3, 4, 6 |
Date range |
|
1, 2, 4 |
Any of (array field) |
|
2, 3, 5 |
Empty array |
|
6 |
Array length |
|
1, 2, 3 |
By id |
|
1, 4 |
Full-text word |
|
4 |
Two points about arrays of objects. Addressing a key inside an array with the [] syntax, as in specs[].k,
flattens the array: the condition passes if any element has that key value, but two conditions on the same array can
be satisfied by different elements. To require that one element satisfies both, wrap the conditions in a nested
condition. On the catalog, where each product has a specs array of {k, v} pairs, the nested filter "a weight
spec below 100" matches only the mouse (id 5), while the two un-nested conditions specs[].k == "weight" and
specs[].v < 100 match ids 1 and 5: the headphones qualify because one element is weight (300) and a
different element is impedance (80):
Filter(must=[
NestedCondition(nested=Nested(
key="specs",
filter=Filter(must=[
FieldCondition(key="k", match=MatchValue(value="weight")),
FieldCondition(key="v", range=Range(lt=100)),
]),
))
])
# scroll result: id 5
Because except is a Python keyword, the Python client builds MatchExcept from a dictionary
(MatchExcept(**{"except": [...]})); over REST the key is simply except.
from qdrant_client.models import (
Filter, FieldCondition, MatchValue, MatchAny, Range,
GeoRadius, GeoPoint, IsNullCondition, PayloadField,
)
results, _ = client.scroll(
collection_name="products",
scroll_filter=Filter(
must=[
FieldCondition(key="category", match=MatchValue(value="audio")),
FieldCondition(key="price", range=Range(lte=300)),
],
should=[
FieldCondition(key="brand", match=MatchAny(any=["acme", "globex"])),
],
must_not=[
FieldCondition(key="discontinued", match=MatchValue(value=True)),
],
),
limit=10,
)
Combining a filter with a vector query
Passing a filter alongside a query vector in the same search request does not run the vector
search first and thin the results afterwards (a post-filter, which can return fewer than limit
hits — or none — when the filter is highly selective). Qdrant’s HNSW graph is filterable: each
node carries enough payload-index information that graph traversal itself skips neighbors the filter
would exclude, so the search keeps exploring until it has limit matching points (or the true
candidate set is exhausted), rather than collecting limit unfiltered neighbors and only then
checking which ones pass. This is the same problem Elasticsearch’s filter inside knn and Solr’s
fq pre-filter into \{!knn\} solve, each with its own mechanism — Dense vector search contrasts Solr’s implicit fq pre-filter, which
restricts the HNSW traversal at the query-parser level, against Qdrant’s richer must/should/
must_not boolean model expressed as one clause inside the same search request.
POST /collections/products/points/query
{
"query": [0.11, -0.95, 0.30, 0.42],
"filter": {
"must": [
{ "key": "category", "match": { "value": "audio" } },
{ "key": "price", "range": { "lte": 300 } }
]
},
"limit": 10
}
Run on the catalog with the query vector [0.85, 0.15, 0.05, 0.05] (close to the audio products), the filter changes
the ranking pool like this:
no filter [(1, 0.995, headphones), (2, 0.994, speaker), (3, 0.924, soundbar)]
audio and price <= 300 [(1, 0.995, headphones), (2, 0.994, speaker)]
in stock [(1, 0.995, headphones), (2, 0.994, speaker), (4, 0.285, keyboard)]
within 5 km of Berlin [(1, 0.995, headphones), (3, 0.924, soundbar), (5, 0.188, mouse)]
category = toys []
Two details are visible here. A filter that matches fewer points than limit returns fewer hits (the first filter
leaves only two) rather than padding the list with non-matching points. And the third line shows the filter
reshaping the ranking: the keyboard, a poor semantic match with score 0.285, still appears because it is the best
remaining in-stock point once the out-of-stock soundbar is excluded. A filter does not demand relevance; if a
minimum quality matters, add a score_threshold to the query as well.
from qdrant_client.models import Filter, FieldCondition, MatchValue, Range
results = client.query_points(
collection_name="products",
query=[0.11, -0.95, 0.30, 0.42],
query_filter=Filter(
must=[
FieldCondition(key="category", match=MatchValue(value="audio")),
FieldCondition(key="price", range=Range(lte=300)),
],
),
limit=10,
).points
Because the filter is honored while the graph is walked, indexing the fields a filter regularly restricts on (via Payload indexes) matters even more than it does for a filter-only query: an unindexed field forces the filter check on each visited node to fall back to a direct payload lookup, which slows exactly the traversal the filterable HNSW graph is meant to keep fast.
Counting, facets and grouping
Filters are not only for search. The same Filter object narrows count and facet, which answer analytics-style
questions without transferring any points:
client.count("products", exact=True, count_filter=Filter(must=[
FieldCondition(key="category", match=MatchValue(value="audio")),
FieldCondition(key="in_stock", match=MatchValue(value=True)),
]))
# count=2
client.facet("products", key="category")
# hits=[FacetValueHit(value='audio', count=3), FacetValueHit(value='computing', count=2),
# FacetValueHit(value='kitchen', count=1)]
The facet result is what a storefront renders as the "Audio (3)" sidebar next to search results; it requires a
keyword index on category. query_points_groups(..., group_by="category", group_size=2) goes one step further and
returns the best hits per category (ids 1 and 2 for audio, ids 4 and 5 for computing, id 6 for kitchen), which avoids a
result page dominated by one category.
Where to go next
-
Vector Indexing & HNSW — how the HNSW graph these filters run over is built and tuned.
-
Hybrid & Sparse Search — combining a filtered dense-vector query like the one above with a sparse-vector query in the same request.
-
Dense vector search — Solr’s
fqimplicit pre-filter combined with\{!knn\}, contrasted against Qdrant’smust/should/must_notfilter model above.