Redisearch: HSET - set index name in RS 2.0

Created on 17 Sep 2020  路  5Comments  路  Source: RediSearch/RediSearch

Hi.

As I understand we are using HSET in RS 2.0 to set some doc into the index. What if we have multiple indexes which can have same fields names, is there a way to specific index name on HSET?

question

Most helpful comment

Hey @botzill , the idea on RediSearch 2.0 is that the index is following your hashes base of key prefix or filter. So if you want to split hashes to different indexes you just need to prefix them and define the indexes to follow the relevant prefix:

127.0.0.1:6379> FT.CREATE idx1 PREFIX 1 idx1: SCHEMA s TEXT
OK
127.0.0.1:6379> FT.CREATE idx2 PREFIX 1 idx2: SCHEMA s TEXT
OK
127.0.0.1:6379> hset idx1:doc1 s foo
(integer) 1
127.0.0.1:6379> hset idx2:doc1 s bar
(integer) 1
127.0.0.1:6379> FT.SEARCH idx1 *
1) (integer) 1
2) "idx1:doc1"
3) 1) "s"
   2) "foo"
127.0.0.1:6379> FT.SEARCH idx2 *
1) (integer) 1
2) "idx2:doc1"
3) 1) "s"
   2) "bar"

All 5 comments

Hey @botzill , the idea on RediSearch 2.0 is that the index is following your hashes base of key prefix or filter. So if you want to split hashes to different indexes you just need to prefix them and define the indexes to follow the relevant prefix:

127.0.0.1:6379> FT.CREATE idx1 PREFIX 1 idx1: SCHEMA s TEXT
OK
127.0.0.1:6379> FT.CREATE idx2 PREFIX 1 idx2: SCHEMA s TEXT
OK
127.0.0.1:6379> hset idx1:doc1 s foo
(integer) 1
127.0.0.1:6379> hset idx2:doc1 s bar
(integer) 1
127.0.0.1:6379> FT.SEARCH idx1 *
1) (integer) 1
2) "idx1:doc1"
3) 1) "s"
   2) "foo"
127.0.0.1:6379> FT.SEARCH idx2 *
1) (integer) 1
2) "idx2:doc1"
3) 1) "s"
   2) "bar"

Thx, @MeirShpilraien, now is clear the concept.

What about {count} in PREFIX, don't really understand that from docs.

The idea is that you can specify multiple prefixes for an index so the count is the number of prefixes you are going to give.

I see, not really aware of the internal structure, but can't that be determined automatically? Like if we add prefixes by space, that can be used to determine them.

Its better defined this way cause then you can also put RediSearch saved words as a prefix (like schema)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mahemoff picture mahemoff  路  4Comments

chuckyz picture chuckyz  路  9Comments

dme-development picture dme-development  路  8Comments

luistrigueiros picture luistrigueiros  路  6Comments

vruizext picture vruizext  路  7Comments