'MongoDb - WildCard $search slow issue - realm query

I have a MongoDB collection with almost 200.000 documents. Inside each document, I have a "Localizations" object containing the "Keywords" field. Contains data like "Air Ducts, Glass Washing, Fuel Pipes, Blow Molding Plastic Parts, Plastic". I created an Index for this field to speed up the search queries. Then I added the below code to the query this way:

$search: {
      wildcard: {
        query: "*" + search + "*",
        allowAnalyzedField: true,
        path: ["Localizations.Keywords"]
      },
    }

But the query is still slow. I tried the compound method and autocomplete indexing but still not fast enough.

Note: results are limited to 20 rows.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source