checking if a hash is in the index

I am trying to debug why certain of my documents (redis hashes) do not end up in my redisearch index.

Is there a way to check if a hash is indexed by redisearch using its redis key - or some other trick?

Thanks

Michael

I do not believe this is possible right now. I was going to suggest using FT.GET, but that doesn’t actually check to see if we know about the document. We should probably do something a bit smarter, like actually check if the document is in the index, and only then retrieve its contents.

With the current version of RediSearch, I am guessing you can try something like “FT.SEARCH idx * INKEYS 1 yourkey”. This is a bit of a hack, but it should work.

Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com

I do not believe this is possible right now. I was going to suggest using FT.GET, but that doesn’t actually check to see if we know about the document. We should probably do something a bit smarter, like actually check if the document is in the index, and only then retrieve its contents.

I think that would be a more predictable expectation of FT.GET - that’s what I thought it did until I tried it/read the docs :wink:

With the current version of RediSearch, I am guessing you can try something like “FT.SEARCH idx * INKEYS 1 yourkey”. This is a bit of a hack, but it should work.

Yes, it does work. Are there any issues using this approach? I only need to find out if a key is in the index for admin purposes, it’s not a user-experience-blocking operation.

Thanks for your help

Michael

It’s certainly a valid use, so I can’t see any issues that might pop up. Now I’m wondering, if we have that, why there is a need for FT.GET at all? I guess in theory, FT.GET is quicker?

Mark Nunberg | Senior Software Engineer
Redis Labs - home of Redis

Email: mark@redislabs.com

You are in a better position to judge if FT.GET would be quicker.

Based on the current implementation of FT.GET, I can’t see how it could be of actual use to anybody since FT.GET == GET.

If anyone is using it with the expectation that it will return 0 for keys not in the index, but that are in redis, they are either using it wrong and/or they haven’t noticed its actual behaviour. So you might even consider just making FT.GET an alias of your INKEYS command, even if it will theoretically break backwards compatibility.

Hey Michael,

If you need it only for administration and checking you can do 'ft.debug docidtoid '. If the result is above zero then the key exists, if you get zero then the key does not exists.
Notice that this is a debug command and might be removed/change in future releases (thats also why its not documented).

Ah, thanks for the tip!