Jetstream kv store - Prefix search / Wildcard search #957
-
Hi, Are there plans to support wild card searching of keys in the Jetstream kv store? For example if these are my keys, I want to be able to pass a prefix to either the
So using
At the moment, I use the Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 11 replies
-
If you use '.' instead in your key name that would present as different tokens to NATS and you can use wildcards to filter there. So if I add the following to a simple KV..
I can then attach a consumer and use wildcards.
|
Beta Was this translation helpful? Give feedback.
-
I tried this and noticed that the performance degenerates a lot when there are a lot of KVs. I used a watcher like this: watcher, err := kv.Watch(main.Person.*", nats.IgnoreDeletes())
if err != nil {
return err
}
defer watcher.Stop()
for entry := range watcher.Updates() {
if entry == nil {
break
}
...
} This gives me the 10 entries in ~400ms on my system. This Method https://github.com/nats-io/nats-server/blob/main/server/filestore.go#L1771 seems to be iterating over all subjects and then filters out all that don't match the wildcards. If i only add 10 entries the watcher completes in 754.831µs. |
Beta Was this translation helpful? Give feedback.
-
Is the KV file based and if so what is your disk subsystem look like? |
Beta Was this translation helpful? Give feedback.
-
We will be looking to make more improvements for 2.10 release around KV, especially with interior delete management but also KV watchers setup and I will check this one as well. If you want to share the underlying stream by doing a snapshot we can use the test data as we work on improvements now that we are getting 2.9.16 out the door. |
Beta Was this translation helpful? Give feedback.
-
You can put it in an object store on demo.nats.io if you want. |
Beta Was this translation helpful? Give feedback.
-
Of course :) nats --context demo object ls discussions_957 The digest/hashsum of the archive is: Digest: SHA-256 d7eca983d0aaf19657b6b7e8b107ce884e3784adaba52bdf1e769e280f78 |
Beta Was this translation helpful? Give feedback.
-
Hello @derekcollison , |
Beta Was this translation helpful? Give feedback.
If you use '.' instead in your key name that would present as different tokens to NATS and you can use wildcards to filter there.
So if I add the following to a simple KV..
I can then attach a consumer and use wildcards.