ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

[Question] After FT.CREATE generates indexes in different environments, the search command (FT.SEARCH) has different results.

Open myjs2023 opened this issue 2 years ago • 5 comments

FT.CREATE在不同环境下生成索引后,搜索命令(FT.SEARCH)有不同的结果。

#CLI 在CLI运行命令行FT.CREATE新建索引后,添加数据,然后在CLI里搜索命令(FT.SEARCH)能正确返回结果. After running the command line FT.CREATE on the CLI to create a new index, add data, and then the search command (FT.SEARCH) in the CLI can correctly return the result.

#ioredis 但是ioredis运行.call('FT.CREATE')后提示[ok]。 添加数据,数据能在RedisInsight里看到, 并再次运行 .call('FT.SEARCH') 后, 它返回 [0] But ioredis prompts [ok] after running db_io.call('FT.CREATE'). Add data, the data can be seen in RedisInsight, and after running .call('FT.SEARCH') again, it returns [0]

/* node.js v18.14.2 docker Docker Desktop 4.18.0 (104112) redisstack https://hub.docker.com/r/redis/redis-stack */

/* // CLI run FT.CREATE 'sssss' ON JSON PREFIX 1 "sdf:" SCHEMA $.name AS name TEXT SORTABLE $.cuisines[*] AS cuisines TAG */

/* node.js code */ const ioreds = require('ioredis'); const db_io = new ioreds();

//ft_create async function ft_create() { let ss = await db_io.call('FT.CREATE', 'ase', 'ON', 'JSON', 'PREFIX', 1, "se:", 'language', 'chinese', 'SCHEMA', "$.name' AS 'name", "TEXT", "SORTABLE", "$.cuisines[*]' AS 'cuisines", 'TAG',) console.log(ss) }

//Running successfully in node.js environment.
//json_set() async function json_set() { let ss = await db_io.call('JSON.SET', 'se:222', '$', '{"name":"ann","cuisines":["555","sz","sh","110"]}') console.log(ss) }

//Running successfully in node.js environment //json_arr() async function json_arr() { let ss = await db_io.call('JSON.ARRAPPEND', 'se:222', '$.cuisines', '"11111111110"') console.log(ss) }

// #1-CLI : After the CLI creates a new index, it runs successfully // #2-NODE.JS : After creating a new index in node.js, the operation fails //ft_search() async function ft_search() { let ss = await db_io.call('FT.SEARCH', 'ase', '@cuisines:{110|555}')
console.log(ss) }

myjs2023 avatar Apr 22 '23 02:04 myjs2023

same issue here, any idea how to fix this?

bossajie avatar Oct 31 '23 08:10 bossajie

I did hit this wall as well. Looking for solution.

FT.SEARCH myIndex * => works

FT.SEARCH myIndex "@myAttribuite:{myValue}" => does not work

PatelVishalJ avatar Nov 01 '23 21:11 PatelVishalJ

Found that I need to pass each word in different argument,

Replacing

let ss = await db_io.call('FT.CREATE', 'ase', 'ON', 'JSON', 'PREFIX', 1, "se:", 'language', 'chinese', 'SCHEMA', "$.name' AS 'name", "TEXT", "SORTABLE", "$.cuisines[*]' AS 'cuisines", 'TAG',)

With

let ss = await db_io.call('FT.CREATE', 'ase', 'ON', 'JSON', 'PREFIX', 1, "se:", 'language', 'chinese', 'SCHEMA', '$.name', 'AS', 'name', 'TEXT', 'SORTABLE', '$.cuisines[*]', 'AS', 'cuisines", 'TAG',)

Should work Basically "$.name AS name" should be replace with three different arguments "$name", "AS", "name".

PatelVishalJ avatar Nov 01 '23 21:11 PatelVishalJ

I also found out that the RETURN is not working. RETURN means you can pass only specific fields which want you get.

bossajie avatar Nov 02 '23 08:11 bossajie

For OP myjs2023. Make sure you installed RSCoord (https://github.com/RediSearch/RSCoordinator) if you are using redis-stack-server(https://hub.docker.com/r/redis/redis-stack-server)

Read more here: https://forum.redis.com/t/anything-to-do-to-get-redisearch-to-search-across-clusters/1943/10

bossajie avatar Nov 02 '23 08:11 bossajie