$lookup with $search when using field as query

Wondering how a $lookup paired with $search would work. I’m expecting the following to return something, but it doesn’t. However, hard coding the query does work.

db.getCollection('recipes').aggregate([
    {
        $match: {}
    },
    {
        $unwind: "$ingredients"
    },
    {
        $lookup: {
          let: { ingredient_name: "$ingredients.name" },
          from: "products",
          as: "product",
          pipeline: [
            {
                $search: {
                    index: "products",
                    text: {
                      query: "$$ingredient_name",
                      path: {
                        wildcard: "*"
                      }
                    }
                }
            },
            {
                $limit: 1
            }
          ]
        }
    }

I am not crazy.

This was already brought up here: https://jira.mongodb.org/browse/SERVER-71036.

Hi @Mahmoud_N_A , confirming that this is a known issue. Can you confirm that what you are trying to achieve is: for every ingredient which exists in the recipes collection, search for matching documents in the products collection. As mentioned in the linked Jira ticket, this could result in unbounded amount of $search queries running – do you have an approximate for the scale that you expect this to be executed at (e.g. how many ingredients will be searched at a time?)

The average goes up to 5-10 ingredients.
The product matches would be ideal to hover around 20. There are metrics like RECALL@20 that are popular to qualify the search response.

@Mahmoud_N_A Got it, thanks for sharing those details. This is something that is under consideration, and I encourage you to watch the linked ticket and share your feedback on our feedback portal!