Relating to new join/reference feature testing in ...
# community-help
s
Relating to new join/reference feature testing in
v0.26.0.rc11
Posted here per @Kishore Nallan request. Applied this to
food
collection
Copy code
{
  "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:
Copy code
{
  "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:
Copy code
{
  "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)"
k
@Harpreet Sangar cc
👍 1
h
We don't support updating the fields with
reference
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
?
s
What you mean, re-index? As in delete all the records in the TS collection, then reload them ?
h
Yeah
s
Ok understood, will that be changed later on, so we can update with a
reference
property and not have to delete everything ?
h
Yeah, I think this would be nice feature to support.
1
s
Copy code
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?
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).
h
Give me some time to think about this.
s
ok got it
Any ideas ?
h
Hey @Shaun Byrnes we have a few ideas but working out what would be the most efficient way to implement this. I'll keep you posted.
s
ok cool
👍🏼 1
Please come back to me when you know next
any progress @Harpreet Sangar
h
Hey Shaun, I'm currently working on adding support for sorting by a reference field. I'll implement your feature request next.
s
ah ok makes sense - the sort by ref field is also useful I think
Ok, I will await that being done before further testing
👍 1
h
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).
This should work by adding
include_fields: $foodBrands(name)
when searching on
food
collection. https://github.com/typesense/typesense/pull/1156
k
Let me build that change.
s
sweet 😄
but you could try the same query with the parent key and confirm that works first, then look at the included/filter by conditions in the scoped key, as well as check the expiry date
k
@Shaun Byrnes We have published
0.26.0.rc68
which contains a syntax change for join. The nest/merge of fields syntax is now through the
strategy
keyword:
Copy code
"include_fields": "$authors(*, strategy: merge)"
s
Ok got it thanks. I presume you mean rc69 tho? As iirc we are already on 68
Also, will it appear in TS cloud for us to update?
k
No you are on
0.26.0.rc67
Yes, it's now available on TS Cloud.
s
ah yes youre correct
ok updatng now
does it look for that keyword
strategy
after last comma yea? That way
$coll(id, strategy, strategy: nest)
would work still correct ?
as there might be a prop in doc called
strategy
h
strategy:
is what the parser looks for. So having
strategy
porp would not interfere.
s
yep makes sense
also as i checked its happy with
strategy:nest
as in no space
1
i guess the regex just check
strategy\:\s*(nest|merge)
or somethink like that