Certainly! The (integer) 0 result from your ft.aggregate command means that no documents matched your query. Let's break down possible reasons and how to fix it.
1. Field Names and Case Sensitivity
Redisearch (the module that provides ft.aggregate) is case-sensitive for both field names and values. In your hash, the field is "gender" with value "Female" (capital "F"):
"gender" => "Female"
But your query is:
ft.aggregate idx:user "@gender:{female}" groupby 1 @country
Here, you're searching for female (all lowercase), but the value in Redis is "Female" (capital "F"). This will not match.
Solution: Match the Case
Try:
ft.aggregate idx:user "@gender:{Female}" groupby 1 @country
2. Index Schema
Make sure your index (idx:user) is set up to index the gender and country fields. You can check your index schema with:
ft.info idx:user
If gender or country are missing, recreate the index or add those fields.
Example index creation:
ft.create idx:user on hash prefix 1 user: schema first_name text last_name text email text gender text country text
3. Data Committed to Index
If you added the hash after creating the index, make sure the key matches the index prefix (user:), and that the index is up to date.
4. Query Syntax
Your query syntax is correct for filtering and grouping, assuming the above are addressed.
Summary
- Check case sensitivity: Use
"Female"not"female". - Ensure fields are indexed:
genderandcountrymust be in the index schema. - Check data and index prefix: The hash key should start with
user:.
Example Working Query
ft.aggregate idx:user "@gender:{Female}" groupby 1 @country
If you want to match case-insensitively, consider storing all values in lowercase and querying with lowercase.
Let me know if you need help checking your index schema or recreating it!