2

I have a query that I need to translate from sql to redis. here is an example of this request

id IN(1,2,4,6)

My schema look's like this:

FT.CREATE log         // Index name
  ON HASH             // Indicates the type of data to index
    PREFIX 1 "log:"   // Tells the index which keys it should index
  SCHEMA
    id        NUMERIC SORTABLE
    finfo     TEXT NOINDEX

https://redis.io/docs/stack/search/reference/query_syntax/

I saw a couple of examples on a site like this:

@id:(1|2|4|6)

but it doesn't work

I want to use a FILTER to send parameters to FT. module. something like that

FILTER "@id:(1|2|4|6)"

1 Answers1

3

with NUMERIC fields you can try range queries, something like:

FT.SEARCH log "@id:[1 6]"

depending the format of your ID field it will be better use TAG instead NUMERIC allowing you to use prefix search like:

FT.SEARCH log "@id:{11*}"

or using OR operator "pipe" for multiple values such as:

FT.SEARCH log "id:{111 | 222 | 333 | 444}" DIALECT 3

more info at the documentation https://redis.io/docs/stack/search/reference/query_syntax/

  • Agree. TAG is probably the way to go here. Unless you plan to do math or range queries on the field, there's really no reason to use NUMERIC. I almost always use TAGs for IDs. – Guy Royse Apr 07 '23 at 14:12
  • if I need to search both in the range and just in the list of values, then it is better to use 2 variables (the type of one will be the number of the second TAG)? – Andrew RutRud Apr 07 '23 at 17:51