We are using Redisearch to insert structured JSON into Redis and searching by content to power autocomplete.
This is how our code looks like in Python:
rs = r.ft("a:a")
schema = (
TextField("$.key", as_name="key"),
NumericField("$.p", as_name="p"),
)
rs.create_index(
schema,
definition=IndexDefinition(
prefix=["a:"], index_type=IndexType.JSON
)
)
With this structure, we are able to insert keys and retrieve by values, like this:
testDic = "{'key': 'glooler-61245', 'val': 'sighgh', 'dom': 'test'}"
r.json().set("a:glooler-erree61245", Path.root_path(), ast.literal_eval(testDic))
prodDic = "{'key': 'booler-erree61245', 'val': 'brouhaha', 'dom': 'prod'}"
r.json().set("a:booler-erree61245", Path.root_path(), ast.literal_eval(prodDic))
rs.search(Query(f"glooler")) # returns only first entry
This works fine, as expected.
But our requirement is that when we are in prod environment, our search should work only on the keys belonging to prod domain (the second key above). How do we specify that in our search query, so that the search doesn’t even look at the data belonging to other domains? There is something like tag in Redis, unable to find out how to use it in our scenario, so a little help would be appreciated.