Something wrong in mongo atlas search string facet

Hey, having similar issues here (mongo 7.0.22). I have a collection with fields created_at (datetime) and keywords (array of str) and atlas search index defined as such:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "created_at": {
        "type": "date"
      },
      "keywords": [
        {
          "type": "token",
          "normalizer": "lowercase"
        },
        {
          "type": "stringFacet"
        }
      ]
    }
  }
}

And I attempt to run counting of keywords in different time windows similar to this:

[
            {
                "$searchMeta": {
                    "index": "index",
                    "facet": {
                        "operator": {
                            "range": {
                                "path": "created_at",
                                "gte": start_datetime,
                                "lt": end_datetime
                            }
                        },
                        "facets": {
                            "topTerms": {
                                "type": "string",
                                "path": "keywords",
                                "numBuckets": 100
                            }
                        }
                    }
                }
            }
        ]

Something really weird happens, where (if I understand things right) I believe only the token indexing should allow me to count frequencies of the keywords in the arrays of selected documents, however A LOT of the documents are not contributing into the buckets. If the index does not have stringFacet mapping the query as shown above returns proper count (total or lowerbound) for the douments but buckets are either empty or show very low counts. When both mappings are present (token and stringfacet) I get (seemingly) proper counts for the keyword frequencies.

1 Like