Closed shenqidebaozi closed 2 years ago
@shenqidebaozi can you please share the full error you get?
@gkorland When running to CreateIndexWithIndexDefinition
, an exception index already exists will be thrown
The effect you want to achieve is that there are target table and group table respectively. After different table data is written, full-text retrieval is carried out respectively
I don't know if my usage is incorrect. Please help me have a look.
I took your example and it worked for me without issues.
package main
import (
"fmt"
"github.com/RediSearch/redisearch-go/redisearch"
)
func main() {
targetClient := redisearch.NewClient("localhost:6379", "target-task#target")
// create schema
targetSchema := redisearch.NewSchema(redisearch.DefaultOptions).
AddField(redisearch.NewTextField("body")).
AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})).
AddField(redisearch.NewNumericField("date"))
if err := targetClient.CreateIndexWithIndexDefinition(targetSchema, redisearch.NewIndexDefinition().AddPrefix("target:")); err != nil {
fmt.Println(err)
}
groupClient := redisearch.NewClient("localhost:6379", "target-task#group")
groupSchema := redisearch.NewSchema(redisearch.DefaultOptions).
AddField(redisearch.NewTextField("body")).
AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})).
AddField(redisearch.NewNumericField("date"))
if err := groupClient.CreateIndexWithIndexDefinition(groupSchema,redisearch.NewIndexDefinition().AddPrefix("group:")); err != nil {
fmt.Println(err)
}
}
I even checked the monitor
and it seems like the commands are sent as expected:
$ redis-cli
127.0.0.1:6379> monitor
OK
1646230856.481580 [0 172.17.0.1:49340] "FT.CREATE" "target-task#target" "ON" "HASH" "PREFIX" "1" "target:" "SCHEMA" "body" "TEXT" "title" "TEXT" "WEIGHT" "5" "SORTABLE" "date" "NUMERIC"
1646230856.481805 [0 172.17.0.1:49342] "FT.CREATE" "target-task#group" "ON" "HASH" "PREFIX" "1" "group:" "SCHEMA" "body" "TEXT" "title" "TEXT" "WEIGHT" "5" "SORTABLE" "date" "NUMERIC"
Are you sure the DB is clear without any index?
Our code is almost the same, but the effect of running here is that after the target is executed, it will prompt "index already exists" when the group is executed.
I'll try it again and see if it's different from you
When I use redisearch, I may use multiple schemas, but I find it seems impossible to create multiple schemas. He always prompts me index already exists. What should be the right way?