Skip to content

Inconsistent behavior between FT.SEARCH and FT.AGGREGATE #545

@mfaulcon

Description

@mfaulcon

In my project, a pair of IQueryable queries are being sent through Redis.OM together that are not behaving as expected. My object is defined as below:

[Document(StorageType = StorageType.Json, Prefixes = [Prefix], IndexName = Prefix + ":idx")]
public class CachedUser : IEntity<Guid>
{
    public const string Prefix = "graph3:user";

    [Indexed(Sortable = true, IndexEmptyAndMissing = false)]
    [RedisIdField]
    public Guid UserId { get; set; }

    // redacted

    [Indexed(Sortable = true, IndexEmptyAndMissing = true)]
    public string? FirstName { get; set; }

    // redacted
}

I'm executing the GraphQL query below:

query users {
  users(where: { firstName: { startsWith: "Ma" } }) {
    totalCount
    items {
      userId
      firstName
      lastName
      email
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
  }
}

At runtime, the query is being translated into the two queries below:

FT.SEARCH graph3:user:idx "(-(ismissing(@FirstName)) (@FirstName:{Ma*}))"
  DIALECT 2
  LIMIT 0 11
  RETURN 12
  UserId AS UserId
  FirstName AS FirstName
  LastName AS LastName
  Email AS Email

and

FT.AGGREGATE graph3:user:idx "@FirstName:{null} (@FirstName:{Ma*})"
  GROUPBY 0
  REDUCE COUNT 0 AS COUNT

The search returns data as expected, but the aggregate returns the count of all documents, instead of only the ones that match the search criteria. If I add DIALECT 2 to the FT.AGGREGATE statement and change the query to match the FT.SEARCH statement, I get the output I expect.

I am running on
Redis 7.4.2
RediSearch 2.10.17
RedisJSON 2.8.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions