RedisSearch return same data irrespective of query

85 views Asked by At

Search Query: FT.search logIndex "@country:{Brazil}" return 3 user_id timestamp country

Returned Values:

enter image description here

instead of country Brazil it is returning the data of China.

I did not find any solution to this problem or may be I am new to RediSearch.

1

There are 1 answers

0
Guy Royse On

Does the record returned have multiple values for the country? If so, I am told that earlier dialects of RediSearch will only return the first one in the list even though it matched another value. You might want to try using DIALECT 3 when you call FT.SEARCH and see if that helps.

Also, you can probably improve your schema:

FT.CREATE logIndex ON JSON PREFIX 1 log
  SCHEMA 
    $.user_id AS user_id TEXT SORTABLE NOINDEX
    $.timestamp AS timestamp TEXT SORTABLE
    $.country AS country TAG SORTABLE

I'm guessing user_id probably has values like groyse, hchandani, or jamesz. TEXT fields are for sentences and paragraphs of human-readable text. I'm guessing this would not describe a user_id. It might work better as a TAG.

If you convert timestamp to an UNIX Epoch datetime (in seconds), store it in your JSON as a number, and index it as NUMERIC then there are date functions when calling FT.AGGREGATE that you can take advantage of.

I would convert it to this:

FT.CREATE logIndex ON JSON PREFIX 1 log
  SCHEMA 
    $.user_id AS user_id TAG SORTABLE NOINDEX
    $.timestamp AS timestamp NUMERIC SORTABLE
    $.country AS country TAG SORTABLE

This doesn't solve your problem above, of course. It's just some extra unsolicited advice! ;)