2

According to the documentation about Atlas Search, it states:

$search must be the first stage of any pipeline it appears in.

Well if that is the case, how do you apply Mongo filters. It seems very counter-intuitive to apply these filters on the output of the search?

We are thinking about using Mongodb full text search as an alternative to Algolia, but this limitation seems weird

Current pipeline:

const pipeline = [
    {
        $search: {
            text: {
                query,
                path: fields,
                fuzzy: {
                    maxEdits: 1,
                    maxExpansions: 50,
                },
            },
        },
    },
    {
        $match: {
            someField: 1,
        },
    },
];
DauleDK
  • 3,313
  • 11
  • 55
  • 98
  • Can you give more details of the filters you would like to apply? It's generally preferable to apply them directly in the $search stage which will be much faster, if it is possible. – Doug May 20 '20 at 23:22
  • Hi @Doug I added the our current implementation - hope it helps. – DauleDK May 24 '20 at 12:13
  • @DauleDK [off topic] "We are thinking about using Mongodb full text search as an alternative to Algolia" How did it go ? I would be keen to share any insights as I was currently investigating Algolia, Atlas Search and Elastic App search. – Gera Zenobi Aug 18 '22 at 10:15
  • Hi @GeraZenobi - mixed. I only have experience with Algolia and Atlas search. The big benefit is no syncing is needed, but take the usecase of searching for a user by email/name. I asked for a blog on this, and no answer. Their support offers little to no help in the community --> just take a look here https://www.mongodb.com/community/forums/t/questions-about-the-text-operator-for-atlas-search-how-to-build-an-effective-search-for-usernames/121709 – DauleDK Aug 18 '22 at 10:25
  • thanks for the quick answer @DauleDK I dare and ask if you have some time ^^ : So I take you haven't migrated yet fully to Atlas Search ? Why you decided to migrate in the first place ? This being not the best place to share feel free to ping me here: https://www.linkedin.com/in/gerardozenobi/ – Gera Zenobi Aug 18 '22 at 10:44

1 Answers1

2

In this case, it may be better to index someField in Atlas Search as a number, as it supports numeric types using the range operator and compound to combine the results. Since the entire query is run in Lucene, it should return results quicker.

const pipeline = [
    {
        $search: {
            compound: {
                should: {
                    text: {
                        query,
                        path: fields,
                        fuzzy: {
                            maxEdits: 1,
                            maxExpansions: 50,
                        },
                    },
                },
                filter: {
                    range: { 
                        path: "someField",
                        lte: 1,
                        gte: 1
                    }
                }
            }

        }
    }
];
Doug
  • 14,387
  • 17
  • 74
  • 104
  • Thanks for providing the example. So using compound we can filter/must/mustNot/should "in Lucene". It kind of makes sense. Would just be so magical if it could expect the "normal" mongoDb $match operators – DauleDK May 26 '20 at 20:36
  • 1
    It is under consideration. Feel free to vote for this issue if you would like to see it prioritized. https://feedback.mongodb.com/forums/924868-atlas-search/suggestions/40517950-allow-search-to-be-a-later-stage-in-the-aggregati – Doug May 26 '20 at 23:23