We are using FT.AGGREGATE to search for companies using wildcards. We are searching based on starts with or contains using "text*" and "*text*" respectively. However, all the companies that should be returned are not returned.
Steps to Replicate:
-
Use the following code and download data.json: ```go package main
import ( "context" "encoding/json" "fmt" "log" "os"
"github.com/go-redis/redis/v8")
type Company struct { Id string
json:"id,omitempty"Code stringjson:"code,omitempty"Name stringjson:"name,omitempty"SortName stringjson:"snm,omitempty"Priority *intjson:"pr,omitempty"}func main() { address := "localhost:6379" // Read JSON file bytes, err := os.ReadFile("data.json") if err != nil { log.Fatalf("Failed to read JSON file: %v", err) }
var companies *[]Company err = json.Unmarshal(bytes, &companies) if err != nil { log.Fatalf("Failed to parse JSON data: %v", err) } // Connect to Redis rdb := redis.NewClient(&redis.Options{ Addr: address, }) ctx := context.Background() // Populate Redis with data from JSON file var operations []any operations = append(operations, "JSON.MSET") var jsonData []byte for _, c := range *companies { jsonData, _ = json.Marshal(c) operations = append(operations, fmt.Sprintf("company:"+c.Id), ".", jsonData) } err = rdb.Do(ctx, operations...).Err() if err != nil { log.Fatalf("Failed to set data in Redis: %v", err) } fmt.Println("Data successfully populated in Redis.")}
and executebash go run .\populate_redis.go`` to run the go script that populates data fromdata.json` file. This will populate all the data required for replicating. Ensure all the data is populated in Redis after running the script.Note: Make sure to change the address variable to match the host and port of the Redis to populate data to.
-
Create index by running the following query:
FT.CREATE idx_company ON JSON PREFIX 1 company: SCHEMA $.snm AS snm TEXT SORTABLE $.name AS name TAG SORTABLE $.id AS id TAG SORTABLE $.code AS code TAG SORTABLE $.pr as pr NUMERIC SORTABLE
Following Are the Issues:
-
Run the following queries in redis cli:
bash FT.AGGREGATE idx_company "(@snm:eri* | @snm:*eri*)" LOAD 5 @id @name @code @snm @pr SORTBY 4 @pr ASC @snm ASC LIMIT 0 10000bash FT.AGGREGATE idx_company "(@snm:erics* | @snm:*erics*)" LOAD 5 @id @name @code @snm @pr SORTBY 4 @pr ASC @snm ASC LIMIT 0 10000bash FT.AGGREGATE idx_company "(@snm:eric* | @snm:*eric*)" LOAD 5 @id @name @code @snm @pr SORTBY 4 @pr ASC @snm ASC LIMIT 0 10000Notice that the company Ericsson B with code ERIC B of id 39405 is returned in all 3 cases, but the one with code ERIBR of id 65290 is not returned in the last case when it should be returned. -
For the same query as above, BRITISH AMERICAN TOBACCO PLC (id 7943) is returned in the last query (eric) but not in the 1st query (eri) when companies that starts with "eric" are a subset of companies that start with "eri".
-
Run the following queries in redis cli:
bash FT.AGGREGATE idx_company "(@snm:alda* | @snm:*alda*)" LOAD 5 @id @name @code @snm @pr SORTBY 4 @pr ASC @snm ASC LIMIT 0 10000bash FT.AGGREGATE idx_company "(@snm:ald* | @snm:*ald*)" LOAD 5 @id @name @code @snm @pr SORTBY 4 @pr ASC @snm ASC LIMIT 0 10000Here, although companies that start with "alda" are subset of companies that start with "ald", companies with name Invalda INVL (id 58053), Kaldal\xc3\xb3n (id 111998) and Vilniaus Baldai (id 93949) are not returned in 2nd query, but returned in 1st query.
Please let us know if you need more information.