redisft.search

SQL IN Operator in Redis by FT.Search/FT.Aggregate


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)"

Solution

  • 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/