[CSHARP-4901] SearchMeta Facet without operator not supported by driver but is supported by api Created: 04/Jan/24  Updated: 08/Jan/24

Status: Backlog
Project: C# Driver
Component/s: None
Affects Version/s: 2.23.0, 2.23.1
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Ben Gelens Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

public FacetSearchDefinition(SearchDefinition<TDocument> @operator, IEnumerable<SearchFacet<TDocument>> facets)
: base(OperatorType.Facet)
{
_operator = Ensure.IsNotNull(@operator, nameof(@operator));
_facets = Ensure.IsNotNull(facets, nameof(facets)).ToArray();
}

according to docs the operator is not required (and testing with compass proves desired results)

https://www.mongodb.com/docs/atlas/atlas-search/facet/#syntax

perator document no Operator to use to perform the facet over. If omitted, Atlas Searchperforms the facet over all documents in the collection.

My usecase: I just want a count of all documents per status so I can report on the statistics



 Comments   
Comment by Boris Dogadov [ 05/Jan/24 ]

Hi ben.gelens@security.wortell.nl,

Thank you for reporting this, and providing a workaround as well.
Additional workaround would be providing the pipeline directly via Json string or BsonDocument.

We will evaluate the priority of this issue. Please follow this ticket for further updates.

Thanks.

Comment by Ben Gelens [ 04/Jan/24 ]

this should work (or an alternate way)

collection.Aggregate()
  .SearchMeta(Builders<MyDoc>.Search.Facet(
    null,
    Builders<MyDoc>.SearchFacet.String("statusFacet", x => x.Status)), "MyIndex")
  .Single(cancellationToken: cancellationToken); 

instead I have to work around the issue now by defining:

collection.Aggregate()
  .SearchMeta(Builders<MyDoc>.Search.Facet(
    Builders<MyDoc>.Search.Regex("status", ".*", true),
    Builders<MyDoc>.SearchFacet.String("statusFacet", x => x.Status)), "MyIndex")
  .Single(cancellationToken: cancellationToken); 

which results in:

"$searchMeta" : {
        "facet" : {
          "operator" : {
            "regex" : {
              "query" : ".*",
              "allowAnalyzedField" : true,
              "path" : "status"
            }
          },
          "facets" : {
            "statusFacet" : {
              "type" : "string",
              "path" : "status"
            }
          }
        },
        "index" : "MyIndex"
      }

while this is what I want it to be:

{
  index: "MyIndex",
  facet: {
    facets: {
      statusFacet: {
        type: "string",
        path: "status",
      },
    },
  },
} 

Comment by PM Bot [ 04/Jan/24 ]

Hi ben.gelens@security.wortell.nl, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.