Are stringFacets supported inside embeddedDocuments?

I need to facet on fields within a collection of documents. For example, mappings look like this:

 "items": {
        "dynamic": false,
        "fields": {
          "position": {
            "type": "stringFacet"
          }
        },
        "type": "embeddedDocuments"
      }

When creating these mappings I’m getting error:

Your index could not be built: Unexpected error: Field must have either TokenStream, String, Reader or Number value; got SortedSetDocValuesFacetField

Are stringFacets not supported inside embeddedDocuments?

1 Like

This is happening because of the text Index defined over the field/document.

Error is coming from Lucene.

MongoDB Atlas Search is a full-text search feature that is built on top of Lucene.

Thanks Anuj,

I’m aware it’s built on Lucene and that’s the source of the underlying error. However, according to the documents this should work. The docs note numeric and date facets are NOT supported on embeddedDocuments, but does not mention incompatibility with stringFacet.

I need to know if stringFacet is also NOT supported and is accidentally omitted by the documentation, or if there is something wrong or missing in my syntax to get it working.

The error you are getting is because you are trying to create a stringFacet on a field that is an embedded document. MongoDB Atlas does not support faceting on embedded documents.

I’m attempting the stringFacet on a field within an embeddedDocument.

The limitiations state:

  • You can’t use embeddedDocuments for date or numeric faceting.

But fail to mention string faceting if this is indeed ALSO a limitation

As per my understanding, MongoDB Atlas does not support faceting on embedded documents, regardless of the type of facet.

Gotcha, Then hopefully someone from the mongo team can hop in here and confirm it is indeed an inaccuracy with the documentation and it should state that no faceting of any kind is supported within embeddedDocuments.

1 Like

Although this is an older question, I found it when searching for faceting information on EmbeddedDocuments.

Although you can’t create a StringFacet within a field indexed as an EmbeddedDocument, you can index the parent field as BOTH a document AND as an embeddedDocuments type.

So, for example, If I had an array field called “Tags” that contained documents with a property of “Name”, my index definition for this field would look like this:

    "Tags": [
        {
          "dynamic": false,
          "fields": {
            "Name": [
              {
                "type": "stringFacet"
              },
              {
                "analyzer": "lucene.keyword",
                "searchAnalyzer": "lucene.keyword",
                "type": "string"
              }
            ]
          },
          "type": "document"
        },
        {
          "dynamic": false,
          "fields": {
            "Name": [
              {
                "analyzer": "lucene.keyword",
                "searchAnalyzer": "lucene.keyword",
                "type": "string"
              }
            ]
          },
          "type": "embeddedDocuments"
        }
      ],

This allows me to text search on the Tags.Name field as a keyword, and allows me to facet on the Tags.Name field too.