Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Index using JSON #138

Closed
xegea opened this issue Feb 12, 2022 · 2 comments
Closed

Create Index using JSON #138

xegea opened this issue Feb 12, 2022 · 2 comments

Comments

@xegea
Copy link

xegea commented Feb 12, 2022

Is it possible to create an index using ON JSON SCHEMA as I do in Redis using Redisearch + RedisJSON together?

Example:
FT.CREATE idx:title ON JSON SCHEMA $.Title AS title TEXT

@akuracy
Copy link

akuracy commented Feb 28, 2022

Hello,

I had the same need, you can use following code:

c := redisearch.NewClient("localhost:6379", "idx:title")

// Create a schema
sc := redisearch.NewSchema(redisearch.DefaultOptions).
	AddField(redisearch.NewTextFieldOptions("$.Title", redisearch.TextFieldOptions{As: "title"}))

// Drop an existing index. If the index does not exist an error is returned
err = c.Drop()

// Create the index with the given schema and definition
id := &redisearch.IndexDefinition{IndexOn: "JSON", Score: -1.0}
if err := c.CreateIndexWithIndexDefinition(sc, id); err != nil {
	log.Fatalln(err)
}

To have As in FieldOptions you have to use master branch since it is not yet released in last version:

go get github.com/RediSearch/redisearch-go/redisearch@master

@gkorland
Copy link
Contributor

gkorland commented Apr 5, 2022

NewIndexDefinition().SetIndexOn(JSON)

See: #111

@gkorland gkorland closed this as completed Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants