Skip to content

kenkyl/redisearch-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

redisearch-examples

Overview

Some basic Python examples of using the RediSearch module to create an index, add documents (stored as Redis Hash objects), and query those documents. RediSearch automatically creates and manages the multiple, complex indexes needed to query the documents stored.

Basic Process

  1. FT.CREATE --> create a new index
  • redis-cli example: FT.CREATE session_index SCHEMA app_oid TAG NOINDEX vnf_id TAG thread_id TAG timestamp NUMERIC SORTABLE ktab TAG
  1. FT.ADD --> add documents to the index
  • redis-cli example: FT.ADD session_index session:<id> app_oid 9999 vnf_id 1234 thread_id 1 timestamp 1595004682 ktab 4321
  1. FT.SEARCH / FT.AGGREGATE --> run queries against the index
  • redis-cli example: FT.SEARCH session_index @ktab:{4321} @vnf_id:{1234} @thread_id:{1} @timestamp:[1595004682 +inf] SORTBY timestamp ASC

Notes

  • It is recommended to use the Quick Start guide and launch a RediSearch Docker container for quick testing. You can also easily load the RediSearch module into an exisitng or new Redis Enterprise database
  • The Python RediSearch library, redisearch-py, is imported separately from the standard redis-py library
  • Small random numbers are used for each of the document fields for simplicity's sake
  • This script does not clear the keys in the redis database. To inspect the indexes and session documents created, run the KEYS command in the redis-cli. To clear out the database, run the FLUSHALL command in the redis-cli (don't run either of these commands in production!)
  • The more times you run the script without clearing the database, the more documents should be returned by the first two query examples
  • For complex queries, create an instance of the Query object, as in the third query example
  • The TAG field type is used for most fields as they are assumed to be exact match queries only. If you need partial or range matching, then a NUMERIC or STRING field should be used accordingly

About

Some basic Python examples of using RediSearch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages