Results of a search operation are less than expected, why?

Last updated 22, Mar 2024

Question

Results of a search operation are less than expected; why?

Answer

In the following example, we depict a scenario where not all the documents are indexed.

FT.CREATE location_idx ON HASH PREFIX 1 location: SCHEMA Name AS name TAG 

HSET location:1 Name Rome Population 3000000
HSET location:2 Name Milan Population 3500000
HSET location:3 Name Naples Population ""

 9) num_docs
10) "3"

FT.CREATE location_idx ON HASH PREFIX 1 location: SCHEMA Name AS name TAG Population AS population NUMERIC SORTABLE

 9) num_docs
10) "2"

Check hash_indexing_failures in FT.INFO, an error may have prevented data from being indexed. In the above example, when a NUMERIC field is enforced, if a string is stored in the hash, the entire hash won't be indexed.

The problem could also be due to timeout, silently interrupting the command, and returning partial results. Try increasing it (either by FT.CONFIG or by the TIMEOUT parameter to FT.SEARCH). The default timeout is 500 ms.

References

Check the documentation to learn more about timeouts configuration.