Troubleshooting Typesense API Sorting Error in Item Collections
TLDR Nikhil encountered a sorting error when using Typesense API due to an optional reference field in the items collection schema. Harpreet and Jason helped debug and identified a bug with sorting in general for 2 fields with the first one being the join field, promising a fix in a forthcoming build.
2
Nov 09, 2023 (3 weeks ago)
Nikhil
02:13 PMv0.26.0.rc29
in typesense cloud to be able to sort items by category name with the help of join.When I make the following API call:-
/collections/items/documents/search?q=*&per_page=100&include_fields=$categories(description),description&sort_by=$categories(description:asc),description:asc
I get the error:-
{
"message": "Could not find a reference for doc 996"
}
We have custom ids in our documents so I am not able to retrieve 996.
Questions:-
1. How do I figure out which one is doc 996 when custom id is specified in our documents?
2. Is there a way for me to ignore a missing reference?
Nikhil
08:55 PMJason
08:58 PMdoc 996 when custom id is specified in our documentsNot sure I understand this... but if you specify an
id
field in the docs, this is what that ID refers to. If you don't set one, it is automatically generated by Typesense.If you didn't set an
id
field explicitly, you could do something like GET /collections/<name>/documents/<id>
(where id would be 996 in your case) to get the document that that ID refers toJason
08:58 PMThere is no way to do this at the moment
Nikhil
09:01 PMNikhil
09:02 PMid
looks like this:-Jason
09:04 PMcategories
collection?Nikhil
09:04 PMNikhil
09:05 PMJason
09:05 PMNikhil
09:05 PMJason
09:06 PMNikhil
09:07 PMconst itemsCollectionSchemaFields: CollectionCreateSchema["fields"] = [
{ name: "id", type: "string", index: true, optional: false, sort: true, infix: true, facet: true },
{ name: "_id", type: "string", index: true, optional: false, sort: false, infix: false },
{ name: "commodityId", type: "string", index: true, optional: true, sort: false, infix: false, facet: true, reference: "commodities.id" }
];
Nikhil
09:07 PMconst commoditiesCollectionCreateSchema: CollectionCreateSchema["fields"] = [
{ name: "id", type: "string", index: true, optional: false, sort: false, infix: false }, // commodityId
{ name: "description", type: "string", index: true, optional: false, sort: true, infix: false },
{ name: "active", type: "bool", index: true, optional: false, sort: false, infix: false }, // useful for deleting all documents
];
Jason
09:15 PM$categories
... could you share that collection's schema?Nikhil
09:16 PMJason
09:17 PMNikhil
09:17 PMNikhil
09:18 PMJason
09:19 PMid
is a special field... If that's the issue, we can try addressing thatJason
09:19 PMNikhil
09:19 PMNikhil
10:08 PMcommodityId
Nikhil
10:10 PMJason
11:06 PMJason
11:06 PMNov 10, 2023 (3 weeks ago)
Nikhil
09:06 AMHarpreet
09:15 AM1
Harpreet
09:38 AM{ name: "commodityId", type: "string", index: true, optional: true, sort: false, infix: false, facet: true, reference: "commodities.id" }
and when we try to compute the sort score of a document that doesn't have a reference on the basis of
$commodities(description:asc)
, it returns this error.Nikhil
09:41 AMNikhil
10:11 AMcommodityId
instead. But I am concerned that next import would duplicate the valuesHarpreet
10:16 AMHarpreet
10:18 AMNikhil
12:21 PMdescription
field, can there be an issue with sorting by both the props? In this case I am trying to sort by commodity description and then item description. However items are not getting sorted even though commodities areHarpreet
12:23 PMHarpreet
12:25 PMNikhil
12:27 PMNikhil
12:28 PMHarpreet
12:32 PMNikhil
12:52 PMHarpreet
12:53 PMNikhil
12:56 PMNikhil
01:02 PM1
Nov 14, 2023 (2 weeks ago)
Harpreet
09:32 AMNikhil
10:40 AMTypesense
Indexed 3015 threads (79% resolved)
Similar Threads
Issue with Query Hangs Identifying Different Collection Field Names
Kanak experiences query hangs when collection field names differ. Ahmed had an issue adding documents to collections, which was self-resolved. Kishore Nallan resolved Kanak's issue with the updated build.
Cold Start Problem with Dynamic Collections
Adrian reported cold start issues with dynamic collections. Jason suggested using wildcard `*` for query_by parameters, upgrading to `0.25.0.rc34`, and clarified conventions. Adrian's issues were resolved but they reported a limitation that will potentially be addressed.
Methods for Fetching, Querying, and Modifying Collections in Typesense
Bill inquired about performing OR queries, querying empty arrays and modifying collections in Typesense. Kishore Nallan explained the current limitations and provided workarounds and recommendations for each case. The conversation also touched upon the usage of cache in Typesense and the workings of the _eval function.
Resolving Issues with Reference Field in v0.26.0.rc11
Shaun reported problems applying the reference field in `v0.26.0.rc11`. The issue made the tested field disappear from UI, and an attempt to fix it resulted in an error. Harpreet suggested re-indexing data and promised to consider improving the feature in future updates. Harpreet is currently working on a related feature - sorting by reference field.
Threading Problem During Multiple Collection Creation and Batch Insertion in Typesense
Johan has a problem with creating multiple collections and batch-inserting documents into Typesense, which is returning results from different collections. Kishore Nallan helps troubleshoot the issue and suggests a potential local race condition, which is fixed in a later build.