Resolving Issues with Reference Field in v0.26.0.rc11
TLDR 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.
2
1
1
Aug 08, 2023 (4 months ago)
Shaun
05:45 AMv0.26.0.rc11
Shaun
05:46 AMApplied this to
food
collection{
"fields": [
{
"name": "foodBrandId",
"drop": true
},
{
"name": "foodBrandId",
"type": "string",
"optional": true,
"facet": false,
"sort": false,
"reference": "foodBrands.id"
}
]
}
Which it said was saved successfully, but I don't think the web UI knows how to show it yet, as that field disappears from the list of the schema when this change was applied (still seems to be found on the actual data).
Trying to make subsequent changes shows: "Error: e: Request failed with HTTP code 400 | Server said: Field
foodBrandId
is not part of collection schema." so seems like all it ended up doing was dropping the field (I just added it back to schema).Furthermore in the sole example given, can we do it this direction for the reference instead to accomplish the same thing:
Schema of
Products
collection:{
"name": "Products",
"fields": [
{"name": "product_id", "type": "string", "reference": "CustomerProductPrices.product_id"},
{"name": "product_name", "type": "string"},
{"name": "product_description", "type": "string"}
]
}
CustomerProductPrices collectionโs schema would store the reference to the product and its associated price:
{
"name": "CustomerProductPrices",
"fields": [
{"name": "customer_id", "type": "string"},
{"name": "product_id", "type": "string"},
{"name": "product_price", "type": "float"}
]
}
Or that wont work?
As when I tried to add the reference in my case about, I get this when trying to query:
"RequestMalformed: Request failed with HTTP code 400 | Server said: Failed to apply reference filter on
foodBrands
collection: Could not find any field in foodBrands
referencing the collection food
."However, I can't add the reference in the
foodBrands
needs to be foods, as many foods could ref/share the same brand, so it needs to be food.foodBrandId
pointing to foodBrands.id
[12:26 PM] My query as follows:
"filter_by": "$foodBrands(id:=foodBrandId)"
Kishore Nallan
05:47 AM1
Harpreet
06:27 AMreference
yet so you'll have to re-index the data. Regarding the Products
collection having the reference field, it won't work since we would be searching for products.If I understood your problem correctly, you have
food
and foodBrands
collections and you would want to search on food
collection and filter by specific foodBrands
?Shaun
06:29 AMHarpreet
06:29 AMShaun
06:30 AMreference
property and not have to delete everything ?Harpreet
06:31 AM1
Shaun
06:32 AMIf I understood your problem correctly, you have food and foodBrands collections and you would want to search on food collection and filter by specific foodBrands?
Yes we have both collections. Both do get searched and currently
food
can filter by foodBrandId
already. We want to add the reference to foodBrands
so that when a food is returned (in any way) we can also grab the foodBrands.name
for example from the other collection (currently food just has the foreign key).Harpreet
07:09 AMShaun
07:09 AMShaun
11:22 PMAug 09, 2023 (4 months ago)
Harpreet
06:13 AMShaun
06:13 AM1
Shaun
06:14 AMAug 14, 2023 (3 months ago)
Shaun
08:05 AMHarpreet
08:10 AMShaun
08:10 AMShaun
08:10 AM1
Aug 17, 2023 (3 months ago)
Harpreet
05:45 AMfoodBrands
so that when a food is returned (in any way) we can also grab the foodBrands.name
for example from the other collection (currently food just has the foreign key).This should work by adding
include_fields: $foodBrands(name)
when searching on food
collection.https://github.com/typesense/typesense/pull/1156
Kishore Nallan
05:46 AMShaun
05:47 AMTypesense
Indexed 3011 threads (79% resolved)
Similar Threads
Troubleshooting Typesense API Sorting Error in Item Collections
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.
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.
Resolving Typesense Analytics "top_queries" Collection Issue
Zain faced issues with typesense analytics and an empty "top_queries" collection. Jason and Kishore Nallan assisted in troubleshooting, identified a bug, and suggested a fix in `0.25.0.rc66`. The fix worked for Zain.
Issue with Join Operation in `CustomerProductPrices` Collection
Nikhil had concerns about adding product prices before the corresponding product and reported a crash when using a filter clause. Harpreet provided a workaround for fetching related products and also suggested a reason for the need of product presence enforcement. The crash could not be reproduced at Harpreet's end.
Trouble in Implementing Deeply Nested Search
Anirudh is struggling to implement a two-level nested search. Jason asked for some specific examples to study the issue. Anirudh provided some material, realizing that adding top fields helped but might over-index. Jason then suggested reporting this issue on GitHub.