Exact match on mebedded documents in atlas search

Looking at the example on https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/ we search for for items tagged school. This search would include items tagged with school, elementary school and high school. If I wanted to search just for items tagged with high school using this query it would return the items tagged with school, elementary school as well as we’re doing a text query. equals seems like an logical operator but it doesn’t work with strings. So the question is how can we do search for an exact match on an embedded document?

Hi @Daniel_Reuterwall , you can achieve an exact text match with embedded documents using the keyword analyzer just like you would with a regular string field. In the example, the search index would be modified to look like this:

{
  name: "default",
  mappings: {
    dynamic: true,
    fields: {
        "items": {
            type: "embeddedDocuments",
            dynamic: true,
            fields: {
                "tags": {
                    type: "string",
                    analyzer: "lucene.keyword"
                }
            }
        }
    }
  }

You can learn more about ways to perform exact matching in Atlas Search here.

3 Likes

Thanks Amy, just what I needed.
Also, great tip with the linked article. Very informative!

Have a great day!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.