I am trying to create Index for array values using Redisearch. here is the code
c := redisearch.NewClient("127.0.0.1:6379", "redisearchDB")
sc := redisearch.NewSchema(redisearch.DefaultOptions).
AddField(redisearch.NewTextField("Code"))
// Drop an existing index. If the index does not exist an error is returned
c.Drop()
// Create the index with the given schema
if err := c.CreateIndex(sc);
err != nil {
log.Fatal(err)
}
doc := redisearch.NewDocument("Test", 1.0)
for i, record := range data {
postRecord := &BlogPost{}
err := json.Unmarshal(record.Value, postRecord)
log.Info("response:", postRecord)
if err != nil {
return err
}
rsp.Cache[i] = &tcache.TKCache{
Code: postRecord.Code,
}
doc.Set("code", postRecord.Code)
}
// Index the document. The API accepts multiple documents at a time
if err := c.Index([]redisearch.Document{doc}...); err != nil {
log.Fatal(err)
}
}
return nil
}
Response needed like this
- (integer) 2
- "Test:1"
-
- "code"
- "ADL"
- "Test:2"
-
- "code"
- "MSL"
How can create index like the above response.