Unknown Command FT.CREATE when creating an index for Redis

huangapple go评论105阅读模式
英文:

Unknown Command FT.CREATE when creating an index for Redis

问题

I can help you with the Chinese translation of the content you provided. Here it is:

我目前正在参考:https://redis.io/docs/clients/python/ 并且在"索引和查询JSON文档"部分,我试图在我的计算机上测试示例代码,但遇到了这个错误:

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`, `$.`,

似乎是源自指南中的以下代码行:

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

我不太确定出了什么问题,如果我删除创建索引的行,我会得到这个错误:

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

任何帮助都将不胜感激。谢谢!

英文:

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

得分: 2

使用FT.CREATE和其他FT命令(RediSearch),您需要一个Redis Stack实例,您可以从以下链接获取:

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

这个实例已经为您预配置了搜索和JSON模块,因此您可以进行搜索并存储JSON或Hashes并进行搜索。

或者,您可以考虑从源代码自行编译搜索模块(以及可能需要的JSON模块),然后通过编辑其配置文件将它们安装到您现有的redis-server中。选择Redis Stack将是最直接的方法。

https://github.com/RediSearch/RediSearch

您还需要从以下链接获取JSON模块:

https://github.com/RedisJSON/RedisJSON

英文:

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

huangapple
  • 本文由 发表于 2023年8月4日 23:57:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837500.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定