Search & browse

Query parameters

All search and browse params - q, semanticWeight, distinctBy, filters, facets, sort, fields, personalization, and the extraParams escape hatch.

Both search and browse share the same parameter surface, including optional distinctBy and personalization (userId, sessionId, personalize). search adds q and optional semanticWeight on top.

Parameter reference

ParamTypeDefaultNotes
qstring-search only, required. The query term. Must be non-empty. Must not exceed 512 characters or 50 words (backend-enforced).
semanticWeightSemanticWeightomittedsearch only. Semantic blend when the collection has enableSemanticSearch and this field is sent. Omit or unset = keyword-only. Values: strict | heavy | default | balanced | light | keyword | off. See Semantic search.
distinctBystring-Optional. On search and browse. One hit per distinct value of that field (for example, styleId returns one hit per keyedTags.styleId).
pagenumber11-based page number.
perPagenumber20Results per page.
facetsstring[]all configuredFacet fields to count. Omit for all; pass explicit list to limit.
filtersKelpFilter[]-Filter clauses - see Filters below.
sortSortItem[]-Multi-key sort - see Sorting.
fieldsstring[]all fieldsRestrict which document fields are returned - see Field projection.
userIdstring-Stable per-visitor id for personalization.
sessionIdstring-Session-scoped behavioral signal.
personalizeboolean-Explicit opt in/out of behavioral re-ranking.
extraParamsRecord<string, unknown>-Merged straight into the request body - escape hatch for unsupported params.

Filters

Filters are an array of clauses, each { field, op?, values }. op defaults to =. Clauses are ANDed together; values within a single = clause are ORed (IN-list).

await kelp.search('products', {
  q: 'running shoe',
  filters: [
    { field: 'brand',  op: '=',     values: ['globex', 'initech'] }, // brand IN (globex, initech)
    { field: 'price',  op: '>',     values: ['0'] },
    { field: 'price',  op: '<=',    values: ['150'] },
    { field: 'rating', op: 'range', values: ['3.5', '5'] },          // inclusive range
    { field: 'status', op: '!=',    values: ['discontinued'] },
  ],
});

Filter operators

opMeaningvalues
=Equals (default)One or more (IN-list)
!=Not equalsOne or more
>Greater thanOne (values[0])
>=Greater than or equalOne (values[0])
<Less thanOne (values[0])
<=Less than or equalOne (values[0])
rangeInclusive rangeTwo ([min, max])

Filterable fields are the collection's configured facet attributes. Filtering on an unconfigured field returns a 400. See Filtering & Facets for more detail on facet configuration.

Combining clauses

  • AND across clauses - every clause must match, even two clauses on the same field.
  • OR within one = clause - values: ['globex', 'initech'] means brand is globex OR initech.
  • There is no OR across different fields.

Custom filter wire shape

If your backend expects a different structure, override serializeFilters on the client:

const kelp = createKelpClient({
  searchUrl: 'https://{TENANT_ID}-search.kelp.click',
  analyticsUrl: 'https://{TENANT_ID}-events.kelp.click',
  apiKey: '...',
  serializeFilters: (clauses) => ({ filter_by: clauses }),
});

Facets

facets controls which fields get value counts in res.facetCounts. Omit it to get counts for all configured facet attributes; pass an explicit list to limit the response.

// Specific facet fields:
const res = await kelp.search('products', {
  q: 'shirt',
  facets: ['gender', 'productCategory', 'vendor', 'status'],
  perPage: 1,
});

// All configured facets (omit the param):
const res2 = await kelp.search('products', { q: 'shirt', perPage: 1 });

res.facetCounts;
// KelpFacetCount[] - [{ field, counts: [{ value, count }] }]

Passing a field that is not a configured facet attribute returns a 400.

Field projection

Use fields to trim the response payload to only the document fields your UI renders. This reduces response size on collections with large documents.

await kelp.search('products', {
  q: 'sunglasses',
  fields: ['id', 'title', 'handle'],
});

Wire body sent:

{ "q": "sunglasses", "fields": ["id", "title", "handle"] }

Accessing a field not listed in fields will be undefined at runtime - TypeScript will not catch this unless you use a narrower document type.

Catalogue personalisation (beta)

Pass a stable per-visitor userId and optionally sessionId to reorder browse or search for that shopper. personalize opts in or out. Same products and filters - only order changes. Merchandising still wins.

await kelp.browse('products', {
  filters: [{ field: 'collections', op: '=', values: ['sandals'] }],
  userId: 'usr_123',
  sessionId: 'sess_abc',
  personalize: true,
});
  • Set personalize: true with a visitor id to opt in.
  • Set personalize: false, or omit the fields, for the standard order (first visit, SEO, admin preview).
  • Each field is only sent when supplied, so omitting all three is byte-identical to a non-personalized request.

Both search and browse accept these fields. See Catalogue personalisation.

extraParams

For anything the typed surface does not cover yet - merged straight into the request body:

await kelp.search('products', {
  q: 'shirt',
  extraParams: { experimental: true },
});

For semantic search use the typed semanticWeight field on search - see Semantic search. Do not route it through extraParams.

On this page