Atlas search and "Scanned Objects / Returned has gone above 1000" alert

I am running into the same problem with this alert: Query Targeting: Scanned Objects / Returned has gone above 1000 - #2 by Pavel_Duchovny

My search looks like this:

    const searchStep = {
      $search: {
        index: 'autocomplete', // optional, defaults to "default"
        compound: {
          minimumShouldMatch: 0, // if one clause fails, still get documents back
          should: [
            {
              autocomplete: {
                query: args.searchText,
                path: 'email',
              },
            },
            {
              autocomplete: {
                query: args.searchText,
                path: 'firstName',
              },
            },
            {
              autocomplete: {
                query: args.searchText,
                path: 'lastName',
              },
            },
          ],
        },
      },
    }

Is there anything I can do?

After the $search I add a $match like

      {
        $match: {
          clinicId: args.clinicId,
        },
     },

Could you consider using filter inside the compound?

Strangely when I add either a filter or a $match, it ignores the $search, it’s not filtering the result of the $earch step it’s just running the $mattch…

So with a filter or match, I get 2300 results. Without it I get 394.

Similarly to Elle’s feedback about filter inside compound I made the following update to your query. It should eliminate this query targeting issue.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.