I have a requirement to implement a black list/ white list concept. We will be getting a user id from an API call and we need to lookup that userid pattern in documents and fetch matching documents.
e.g. user id received - 092712345
doc1{
code: A
uid: 09*
}
doc2{
code: B
uid: 0927*
}
doc2{
code: C
uid: 05*
}
In this situation, I want to be able to pull doc2 and return code as B as it matches the input userid most closely. There is no hard requirement to store uid as 09*. It can be whatever format (regex or anything else) that will fulfill the need.
Select digit, code from pattern
where (digit = 9 and uid = '092712345') or
... or
(digit = 2 and uid= '09') or
(digit = 1 and uid= '0') order by digit Desc
You can utilize covering index to optimize the performance as I expect the size of the index would not have huge impact to the memory size in this case.
When you use query, Document ID can be anything while I assume that the above Document ID rule ensures no redundant pattern.
Or, the same operation could be logically realized with KV API by using the above Document ID examples (‘2-09’, ‘4-0927’…), although the programing could be a little bit complicated in comparison to the above query. The advantage is no dependency to query and index services.
There could be better ideas though, I hope this helps.
In either case it the server doesn’t actually care which element of the statement is the parameter and which is the document field - you specify them as suits your needs; the documents are returned if the condition returns true.
<edit>
These of course assume strings for the pattern document field and parameter value.
</edit>