2

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

  1. (integer) 2
  2. "Test:1"
    1. "code"
    2. "ADL"
  3. "Test:2"
    1. "code"
    2. "MSL"

How can create index like the above response.

  • 1
    Did you check the Tag type? https://oss.redislabs.com/redisearch/Tags/ – Guy Korland Apr 08 '21 at 07:29
  • Are you looking for the [`RETURN`](https://oss.redislabs.com/redisearch/Commands/) keyword in the search syntax? Unclear what you are asking - issue with query or the response? – ficuscr May 12 '21 at 03:21

0 Answers0