如何解决为数组值创建索引
我正在尝试使用 Redisearch 为数组值创建索引。 这是代码
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
}
需要这样的回复
如何像上面的响应那样创建索引。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。