Unknown Command FT.CREATE when creating an index for Redis

2.4k Views Asked by At

I am currently following: https://redis.io/docs/clients/python/ and in the "Indexing and querying JSON documents" section, I am trying to test out the example code on my computer but I run into this error:

redis.exceptions.ResponseError: unknown command `FT.CREATE`, with args beginning with: `idx:users`, `ON`, `JSON`, `PREFIX`, `1`, `user:`, `SCORE`, `1.0`, `SCHEMA`, `$.name`, `AS`, `name`, `TEXT`, `WEIGHT`, `1.0`, `$.`,

which seems to be stemming from these lines of code from the guide:

rs.create_index(
    schema,
    definition=IndexDefinition(
        prefix=["user:"], index_type=IndexType.JSON
    )
)

I am not too sure what's wrong and if I delete the create index lines, I get this error:

AttributeError: type object 'Path' has no attribute 'root_path'

Any help would be appreciated. Thanks!

1

There are 1 best solutions below

0
Simon Prickett On

to use the FT.CREATE and other FT commands (RediSearch) you'll need a Redis Stack instance which you can get from here:

https://redis.io/docs/getting-started/install-stack/

This has the search and JSON modules pre-configured for you so you can use search and also store JSON natively and search over that or Hashes.

Alternatively you could consider compiling the search module (and potentially JSON if you want that too) yourself from source and installing them into your existing redis-server by editing its configuration file. Going with Redis Stack would be the most straightforward approach.

https://github.com/RediSearch/RediSearch

You'd also need the JSON module from:

https://github.com/RedisJSON/RedisJSON