Skip to main content
Morphik lets you filter documents and chunks directly in the database using a concise JSON filter syntax. The same structure powers the REST API, Python SDK (sync + async), folder helpers, and UserScope, so you can define a filter once and reuse it everywhere.
Prefer server-side filters over client-side post-processing. You’ll reduce bandwidth, improve performance, and keep behavior consistent between endpoints.

Where Filters Apply

You can pass filters (or document_filters) to:

Quick Start

Typed Metadata

Typed comparisons (numbers, decimals, dates, datetimes) rely on metadata_types. Supply the per-field hints during ingest or metadata updates:
If you omit a hint, Morphik infers one automatically for simple scalars, but explicitly declaring types is recommended for reliable range queries.

DateTime and Timezone Behavior

Morphik preserves your timezone format exactly as provided: SDK Type Reconstruction: When you retrieve a Document via the Python SDK, datetime/date/decimal values in metadata are automatically reconstructed to their Python types using the metadata_types hints. This means you get back what you put in:

Mixed Timezone Formats

Morphik handles mixed formats correctly - filtering and comparisons work even if some documents have naive datetimes and others have timezone-aware ones:
Python comparisons fail with mixed formats. If you retrieve mixed-format datetimes and compare them locally, Python raises TypeError:
Recommendation: Stay consistent - pick one format (preferably timezone-aware with UTC) and use it throughout. Let Morphik handle filtering rather than sorting in Python.

Implicit vs Explicit Syntax

  • Implicit equality – Bare key/value pairs ({"status": "active"}) use JSON containment and are ideal for simple matching. They also check whether an array contains the value.
  • Explicit operators – Wrap a field in an operator object to unlock typed comparisons, set logic, regex, substring checks, etc. ({"status": {"$ne": "archived"}}).

Operator Reference

Equality & Comparison

Set Membership

Type & Existence

String & Pattern Matching

Logical Composition

Mix logical operators freely with field-level operators for complex expressions.

Common Patterns

Current Window Between Start/End

Folder/User Scope plus Metadata

Array Membership & Substring

Troubleshooting

  • “Unsupported metadata filter operator …” – Double-check spelling and operand type (lists for $in, non-empty arrays for $and, etc.).
  • “Metadata field … expects type …” – The server couldn’t coerce the operand to the declared type. Ensure numbers/dates are valid JSON scalars or native Python types before serialization.
  • Range query returns nothing – Confirm the target documents were ingested/updated with the corresponding metadata_types. Re-ingest or call update_document_metadata with the proper type hints if necessary.
Still stuck? Share your filter payload and endpoint at founders@morphik.ai or on Discord.