Search code examples
mongodbaggregation-frameworkmongodb-atlas-search

MongoDB atlas search is not as efficient as expected


I have the problem that my search is not as efficient as expected. I've already checked out several options to improve the search, but unfortunately that didn't work. (For example, using other index and search Analyzer, wildcard search instead of text search, ...)

The search should only search certain fields and not the entire document. Unfortunately, other fields that were not specified are also searched.

What could be the reason for this?

Thanks in advance and best regards

Aggregation Query

[
    {
        "$search":{
            "compound":{
                "should":[
                    {
                        "text":{
                            "query":"*searchTerm*",
                            "path":[
                                "companyName",
                                "customerNameAddition"
                            ],
                            "score":{
                                "boost":{
                                    "value":3
                                }
                            }
                        }
                    },
                    {
                        "text":{
                            "query":"*searchTerm*",
                            "path":"customerNumber",
                            "score":{
                                "boost":{
                                    "value":2
                                }
                            }
                        }
                    },
                    {
                        "text":{
                            "query":"*searchTerm*",
                            "path":"email"
                        }
                    }
                ]
            }
        }
    },
    {
        "$limit":15
    }
]

Index OverviewIndex Overview


Solution

  • You need to turn dynamic mapping to "off" in order to not dynamically index all of your fields.

    Also for your email field, you may consider using uaxUrlEmail