Skip to main content
Version: 2.0

Metadata Examples and Use Cases

Metadata filters enable highly versatile and granular control over query results. This section provides real-world examples and use cases to illustrate how metadata filters can be applied to solve common business and technical challenges.

Language-specific filtering​

In multilingual documents, different sections may be in different languages. Use part-level metadata to target specific language segments.

**Example: **Filter for German-language customer reviews with a rating higher than 3 stars.

LANGUAGE FILTER

Code example with sql syntax.
1

The lang metadata tag used in this example is detected and set automatically by the platform at indexing time. It's set at the part level for accuracy, because a single document may contain content in multiple languages.

Date-specific document retrieval​

More complicated expressions are possible, such as the one below, which checks for documents with a publication date in 2021.

Example: Retrieve documents published in 2021 using epoch time.

DATA-SPECIFIC FILTER

Code example with sql syntax.
1

Here, pub_epoch stores the date in epoch time.

You can find a full list of supported operations on the Functions and Operators page, and a full list of how to specify literals on Data Types.

Filter by document status​

For auditing purposes, you may want to limit results to documents marked as Published instead of Draft:

doc.status = 'Published'

Filter by custom tag​

Custom metadata fields enable filtering based on business-specific criteria, such as priority, category, or internal tags.

Example: Filter documents tagged as High Priority in the Technology category.

BUSINESS-SPECIFIC CRITERIA

Code example with sql syntax.
1

Example query with a document-level filter​

This example asks the question "What are the key benefits of cloud computing?" from the Cloud Computing References corpus. Within the corpora object, we specified a metadata_filter to filter though published documents with "metadata_filter": "doc.status = 'Published'",

METADATA EXAMPLE

Code example with json syntax.
1

Example response with a document-level filter​

The example response returns documents with a "status": "Published", in the document metadata. This response also shows other metadata associated with each document_id.

RESPONSE EXAMPLE

Code example with json syntax.
1

Example query with part-level metadata​

Now let's send a query with part-level meta for part.concept = 'Overview'.

We will only change the metadata_filter value from the previous example so that it filters for this part-level metadata:

METADATA EXAMPLE

Code example with json syntax.
1

Example response with part-level metadata​

PART-LEVEL METADATA EXAMPLE

Code example with json syntax.
1