3

I have a collection with 11M records, which contains among other properties, a "Name" property with a client name:

{
    "Name" : "Teressa Bella"
}

I have created an Atlas Search index on the "Name" field with the following definition:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "Name": {
        "analyzer": "lucene.standard",
        "type": "string"
      }
    }
  }
}

My use case counting all the documents that match a certain term which I'm doing like so:

db.getCollection('recipients').aggregate([
  {
    $search: {
      "text": {
        "query": "Teressa",
        "path": "Name"
      }
    }
  },
  {
    $count: "total"
  }
])

The problem is that this query takes about 40s to complete on an M30 Atlas cluster (sometimes 10s or 20s if entirely fetched from memory, I presume). Is this within the expected execution time for matching a term on 11M documents? I would appreciate any suggestions on how i can optimize this kind of query.

djed
  • 141
  • 10

0 Answers0