Paul Wallnöfer
09/12/2025, 8:47 AM770MB and the memory usage of the server is about 5.5GB. What am i missing here? The collection schema is appended at the end.
Now onto the paginated query. I have a paginated filterable table in my application
and if i just fetch the first page of the table, the query looks like this:
{
"q": "*",
"page": 1,
"per_page": 10,
"limit_hits": 20,
"include_fields": ", $in_use(), $manufacturers(), $distributors(), $product_bans(*)",
"filter_by": "(id:* || $in_use(id:) || $tenant_product_distributors(id:) || $product_bans(id:*))",
"sort_by": "eid:ASC"
}
This query takes about 1.4s to finish and i was wondering if i am doing the left joins wrong, because in SQL this takes a few milliseconds.
Now if i am trying to filter by a distributor like so:
{
"q": "*",
"page": 1,
"per_page": 10,
"limit_hits": 20,
"include_fields": ", $in_use(), $manufacturers(), $distributors(), $product_bans(*)",
"filter_by": "$tenant_product_distributors(distributor_id:=2) && (id:* || $in_use(id:) || $product_bans(id:))",
"sort_by": "eid:ASC"
}
The query now takes only 600ms. How is a query faster with a filter on a joined collection than without any filters at all.
I get that there will be less documents to join but does this really add up to cutting the the query time in half?
Thank you in advance.
Here is the collection schema i am using:
[
{
"name": "products",
"fields":
[
{ "name": "eid", "type": "int32", "sort": true },
{ "name": "name", "type": "string", "sort": true },
{ "name": "number", "type": "string", "sort": true },
{
"name": "manufacturer_id",
"type": "string",
"reference": "manufacturers.id"
},
{ "name": "gs1", "type": "string" },
{ "name": "hibc", "type": "string" },
{ "name": "ean8", "type": "string" },
{ "name": "ean13", "type": "string" }
],
"default_sorting_field": "eid"
},
{
"name": "tenant_product_distributors",
"fields":
[
{ "name": "tenant_id", "type": "int32", "index": false },
{
"name": "distributor_id",
"type": "string",
"reference": "distributors.id"
},
{ "name": "product_id", "type": "string", "reference": "products.id" }
]
},
{
"name": "in_use",
"fields":
[
{ "name": "tenant_id", "type": "int32", "index": false },
{ "name": "product_id", "type": "string", "reference": "products.id" },
{ "name": "in_use", "type": "bool", "sort": true }
],
"default_sorting_field": "in_use"
},
{
"name": "product_bans",
"fields":
[
{ "name": "tenant_id", "type": "int32", "index": false },
{ "name": "product_id", "type": "string", "reference": "products.id" },
{ "name": "ban", "type": "bool", "sort": true }
],
"default_sorting_field": "ban"
},
{ "name": "manufacturers", "fields": [{ "name": "name", "type": "string" }] },
{
"name": "manufacturer_prefixes",
"fields":
[
{
"name": "manufacturer_id",
"type": "string",
"reference": "manufacturers.id"
},
{ "name": "prefix", "type": "string" },
{ "name": "prefix_type", "type": "int32" }
]
},
{ "name": "distributors", "fields": [{ "name": "name", "type": "string" }] }
]Harpreet Sangar
09/12/2025, 9:59 AM{
"q": "*",
"page": 1,
"per_page": 10,
"limit_hits": 20,
"include_fields": ", $in_use(), $manufacturers(), $distributors(), $product_bans(*)",
"filter_by": "(id:* || $in_use(id:) || $tenant_product_distributors(id:) || $product_bans(id:*))",
"sort_by": "eid:ASC"
}
maybe I can suggest a better query?Paul Wallnöfer
09/12/2025, 10:08 AMHarpreet Sangar
09/12/2025, 2:09 PM{
"q": "*",
"page": 1,
"per_page": 10,
"limit_hits": 20,
"include_fields": ", $in_use(*), $manufacturers(*), $distributors(*), $product_bans(*), $tenant_product_distributors(*)",
"filter_by": "id:* || $tenant_product_distributors(id:)",
"sort_by": "eid:ASC"
}
Can you check if this reduces the time from 1.4s?Paul Wallnöfer
09/15/2025, 6:18 AMHarpreet Sangar
09/15/2025, 6:30 AMin_use is missing? product_bans is still returned?Paul Wallnöfer
09/15/2025, 7:21 AMin_use nor product_bans is returnedHarpreet Sangar
09/15/2025, 7:24 AMPaul Wallnöfer
09/15/2025, 10:33 AMPaul Wallnöfer
09/15/2025, 10:34 AMcurl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"name": "products",
"fields":
[
{ "name": "eid", "type": "int32", "sort": true },
{ "name": "name", "type": "string", "sort": true },
{ "name": "number", "type": "string", "sort": true },
{
"name": "manufacturer_id",
"type": "string",
"reference": "manufacturers.id"
},
{ "name": "gs1", "type": "string" },
{ "name": "hibc", "type": "string" },
{ "name": "ean8", "type": "string" },
{ "name": "ean13", "type": "string" }
],
"default_sorting_field": "eid"
}' | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"name": "tenant_product_distributors",
"fields":
[
{ "name": "tenant_id", "type": "int32", "index": false },
{
"name": "distributor_id",
"type": "string",
"reference": "distributors.id"
},
{ "name": "product_id", "type": "string", "reference": "products.id" }
]
}' | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"name": "in_use",
"fields":
[
{ "name": "tenant_id", "type": "int32", "index": false },
{ "name": "product_id", "type": "string", "reference": "products.id" },
{ "name": "in_use", "type": "bool", "sort": true }
],
"default_sorting_field": "in_use"
}' | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"name": "product_bans",
"fields":
[
{ "name": "tenant_id", "type": "int32", "index": false },
{ "name": "product_id", "type": "string", "reference": "products.id" },
{ "name": "ban", "type": "bool", "sort": true }
],
"default_sorting_field": "ban"
}' | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{ "name": "manufacturers", "fields": [{ "name": "name", "type": "string" }] }' | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"name": "manufacturer_prefixes",
"fields":
[
{
"name": "manufacturer_id",
"type": "string",
"reference": "manufacturers.id"
},
{ "name": "prefix", "type": "string" },
{ "name": "prefix_type", "type": "int32" }
]
}' | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{ "name": "distributors", "fields": [{ "name": "name", "type": "string" }] }' | jq
curl -s "$TYPESENSE_HOST/collections/products/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{
"id": "3",
"name": "SR Vivodent PE Set of 6 UA11 1A",
"number": "504377",
"ean13": "",
"ean8": "",
"eid": 3,
"gs1": "",
"hibc": "DIVO5043771",
"manufacturer_id": "1"
}' | jq
curl -s "$TYPESENSE_HOST/collections/in_use/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{
"id": "12",
"in_use": false,
"product_id": "3",
"tenant_id": 1
}' | jq
curl -s "$TYPESENSE_HOST/collections/product_bans/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{
"ban": false,
"id": "8",
"product_id": "3",
"tenant_id": 0
}' | jq
curl -s "$TYPESENSE_HOST/collections/tenant_product_distributors/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{
"distributor_id": "1",
"id": "25",
"product_id": "3",
"tenant_id": 1
}' | jq
curl -s "$TYPESENSE_HOST/collections/distributors/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{
"id": "1",
"name": "Ivoclar Vivadent GmbH (DE)"
}' | jq
curl -s "$TYPESENSE_HOST/collections/manufacturers/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{
"id": "1",
"name": "Ivoclar"
}' | jqHarpreet Sangar
09/16/2025, 3:05 AMPaul Wallnöfer
09/22/2025, 6:56 AMHarpreet Sangar
09/22/2025, 7:02 AMPaul Wallnöfer
09/22/2025, 7:14 AMPaul Wallnöfer
10/24/2025, 6:27 AMHarpreet Sangar
10/24/2025, 8:26 AMHarpreet Sangar
10/24/2025, 8:27 AMPaul Wallnöfer
10/24/2025, 8:32 AM