Redisearch 2.0 what exactly is PREFIX {count} {prefix} in FT.CREATE?

Is there any example for this? I am just migrating from 1.6 and wondering how and if to use it?

Thanks

1 Like

Take a look here:

Hello,

In RediSearch 2.0, the indexing process has changed compared to 1.x.

When before (1.x) you had to create an index and then use FT.ADD to index the data, in RediSearch 2.0 the flow is different and more natural for the developer:

  1. You create an index and tell the engine what to index.
  2. The prefix defines the list of key prefix that will be look at for this index.

Let’s say that you have many key patterns in your application, for example:

  • actor:*
  • movie:*
  • tvshow:*
  • theater:*

all of these being HASHES. (and you may have many other keys)

Using the prefix you can tell which key to index for each index, for example you want to create 2 indices:

  • idx:actor to search actors
  • idx:movie to search movies and tvshows

You will use the prefix for that, as follow:

> FT.CREATE idx:actor ON hash PREFIX 1 "actor:" SCHEMA name TEXT ...

> FT.CREATE idx:movies ON hash PREFIX 2 "movie:" "tvshow" SCHEMA name TEXT ...

So this will index all existing data and stay up to date based on the index definition. using PREFIX 2 "movie:" "tvshow" you will have all movies and tvshow in the same index

PS: RediSearch 2.0 will soon be launch officially with updated documentation, blog post and tutorial. (stay tuned)

Regards
Tug

1 Like

Looking forward to the 2.0 documentation!

1 Like

Hello,

RediSearch 2.0 has been released, some content: