2

我正在尝试使用 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
}

需要这样的回应

  1. (整数) 2
  2. “测试:1”
    1. “代码”
    2. “ADL”
  3. “测试:2”
    1. “代码”
    2. “MSL”

如何创建类似上述响应的索引。

4

0 回答 0