Filter by metadata

Beta

This feature is in beta. The API may change.

Search with structured filters on any metadata field. Filters are applied before results are returned — only documents that match every condition are returned.


1. Index with metadata

Filters operate on the metadata you attach at index time. Include every field you want to filter on.

import { Etoile } from "@etoile-dev/client";

const etoile = new Etoile({
apiKey: process.env.ETOILE_API_KEY,
});

await etoile.index({
id: "product-1",
collection: "products",
title: "Ultraboost 22",
content: "Lightweight running shoe with responsive cushioning...",
metadata: {
  category: "running",
  brand: "Adidas",
  price: 130,
  rating: 4.6,
  inStock: true,
},
});

2. Search with filters

Pass a filters array to narrow results by metadata. All filters are combined with AND logic.

const { results } = await etoile.search({
query: "comfortable everyday shoe",
collections: ["products"],
filters: [
  { key: "category", operator: "in", value: ["running", "training"] },
  { key: "price",    operator: "lte", value: 150 },
  { key: "rating",   operator: "gte", value: 4.0 },
],
});

Supported operators

ParameterTypeDescription
eqstring | number | booleanEqual to the given value.
neqstring | number | booleanNot equal to the given value.
gtnumberGreater than.
gtenumberGreater than or equal.
ltnumberLess than.
ltenumberLess than or equal.
instring[]Matches any value in the list.
not_instring[]Matches none of the values in the list.
contains_allstring[]Metadata array contains all of the given values.
contains_anystring[]Metadata array contains at least one of the given values.
contains_nonestring[]Metadata array contains none of the given values.

Related