Hi all, Im trying to do a very basic JOIN and im ...
# community-help
l
Hi all, Im trying to do a very basic JOIN and im having issues. iv tried to follow the docs exactly but the referenced object just isnt getting included in the result. here is my query:
Copy code
const searchParams = {
      q: searchText === "" ? "*" : searchText,
      query_by: "title,description",
      exclude_fields: "embedding",
      page: 1,
      per_page: 16,
      include_fields: "$marketplaces(*)",
    };
    const results = await typesense.collections("items").documents().search(searchParams);
    console.log(results);
and here is the relevant part of my schema:
Copy code
export const itemSESchema: CollectionCreateSchema = {
  name: "items",
  enable_nested_fields: true,
  fields: [
    // marketplace fields
    {
      name: "marketplaceId",
      type: "string",
      reference: "marketplaces.id",
    },
but this is my return result:
Copy code
{
    "basePrice": 199.75,
    "category": "Special Event and Party",
    "createdAt": 1740586782838,
    "description": "Make sure this fits by entering your model number. | SERPENTINE DESIGN: Allows Magic Tracks to bend, flex, and curve in any direction",
    "id": "itm-157d5-613e08-0b77",
    "images": [
        {
            "id": "fil-7d71685-7de6682b-be2354",
            "url": "<https://images-na.ssl-images-amazon.com/images/I/61DMdeT-7hL.jpg>"
        },
        {
            "id": "fil-637909c-529f5a5f-cfeb2c",
            "url": "<https://images-na.ssl-images-amazon.com/images/I/519AkYDZmVL.jpg>"
        },
    ],
    "marketplaceId": "mkp-95f4d-ffaf04-31ab",
    "nonAvailability": [],
    "quantity": 2,
    "status": "active",
    "tags": [],
    "title": "Ontel Magic Tracks The Amazing Racetrack That Can Bend, Flex and Glow - As Seen On TV",
    "updatedAt": 1740586782838
}
it does not include marketplaces: {//… data}. Im not really sure what im doing wrong since i know for sure that there is a marketplaces document with such id. what does it mean if the marketplaces field is just not included?
j
Could you make sure you're on v28 of Typesense?
l
I am indeed. i actually realized that it started working after i reindexed my items collection. does marketplaces collection have to be indexed BEFORE the items collection? i unknowingly indexed items before marketplaces (items contains a reference to marketplaces), and it wasnt working that way
j
Yeah the order of indexing matters by default. The reference needs to exist ahead of time. But there's this
async_reference
feature you can use, but has to be set up ahead of time: https://github.com/typesense/typesense-website/pull/298/files
l
okay, great thanks so much. btw really enjoying typesense over algolia so far, and really appreciate your guys prompt responses. much respect 🙏
🙌 1
j
That's great to hear! Thank you for the kind words!