This recipe demonstrates building a searchable employee directory with autocomplete, fuzzy name matching, and department filtering.
Schema Design#
The schema uses nested fields for profile data and exact matching for identifiers:
Sample Data#
Waiting for Indexing#
Index updates are batched for performance, so newly added data may not appear in search results immediately.
Use SEARCH.WAITINDEXING to ensure all pending updates are processed before querying:
Autocomplete Search#
Use $fuzzy with prefix: true for search-as-you-type functionality. This approach handles
both incomplete words and typos, providing a more forgiving autocomplete experience:
Fuzzy Name Search#
Handle typos and misspellings in name searches:
Exact Username/Email Lookup#
Find users by exact username or email:
Department and Role Filtering#
Filter users by department, role, or both:
Search by Skills in Bio#
Find users with specific skills or expertise:
Admin User Search#
Find administrators or users with specific permissions:
Key Takeaways#
- Use
NOTOKENIZEfor usernames, emails, and exact-match identifiers - Use
NOSTEMfor proper nouns like names to prevent incorrect stemming - Use
$fuzzywithprefix: truefor search-as-you-type autocomplete with typo tolerance - Use
$fuzzyto handle typos in name searches - Combine nested field paths (e.g.,
profile.firstName) for structured data