Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got ERR unknown command FT.CREATE error when creating an index ? #63

Open
sergeynilov opened this issue Feb 24, 2023 · 1 comment
Open
Labels
question Further information is requested

Comments

@sergeynilov
Copy link

sergeynilov commented Feb 24, 2023

I added macfja/redisearch ^2.2 to my laravel 9.48 app and got errors :

ERR unknown command `FT.CREATE`, with args beginning with: `articleIndices`, `SCHEMA`, `title`, `TEXT`, `SORTABLE`,
when creating index with code:

    public function createIndex(): self
    {
        $clientFacade = new ClientFacade();
        \Log::info(varDump($clientFacade, ' -1 createIndex $clientFacade::'));
        $redisClient =  $clientFacade->getClient(new \Predis\Client(/* ... */));
        $builder = new \MacFJA\RediSearch\IndexBuilder();
        \Log::info(varDump($builder, ' -1 $builder::'));

        $builder
            ->setIndex('articleIndices')
            ->addTextField('title', false, null, null, true)
            ->create($redisClient);  // Error pointing at this line

Making dumps of 2 vars above I see in log file :

[2023-02-24 07:42:12] local.INFO:  (Object of MacFJA\RediSearch\Redis\Client\ClientFacade) : -1 createIndex $clientFacade:: : Array
(
    [ MacFJA\RediSearch\Redis\Client\ClientFacade factories] => Array
        (
            [0] => MacFJA\RediSearch\Redis\Client\PredisClient
            [1] => MacFJA\RediSearch\Redis\Client\CredisClient
            [2] => MacFJA\RediSearch\Redis\Client\PhpredisClient
            [3] => MacFJA\RediSearch\Redis\Client\PhpiredisClient
            [4] => MacFJA\RediSearch\Redis\Client\CheprasovRedisClient
            [5] => MacFJA\RediSearch\Redis\Client\RedisentClient
            [6] => MacFJA\RediSearch\Redis\Client\RediskaClient
            [7] => MacFJA\RediSearch\Redis\Client\AmpRedisClient
            [8] => MacFJA\RediSearch\Redis\Client\TinyRedisClient
        )

)

[2023-02-24 07:42:12] local.INFO:  (Object of MacFJA\RediSearch\IndexBuilder) : -1 $builder:: : Array
(
    [ MacFJA\RediSearch\IndexBuilder index] =>
    [ MacFJA\RediSearch\IndexBuilder structure] =>
    [ MacFJA\RediSearch\IndexBuilder prefixes] => Array
        (
        )

    [ MacFJA\RediSearch\IndexBuilder filter] =>
    [ MacFJA\RediSearch\IndexBuilder defaultLanguage] =>
    [ MacFJA\RediSearch\IndexBuilder languageField] =>
    [ MacFJA\RediSearch\IndexBuilder defaultScore] =>
    [ MacFJA\RediSearch\IndexBuilder scoreField] =>
    [ MacFJA\RediSearch\IndexBuilder payloadField] =>
    [ MacFJA\RediSearch\IndexBuilder maxTextFields] =>
    [ MacFJA\RediSearch\IndexBuilder temporary] =>
    [ MacFJA\RediSearch\IndexBuilder noOffsets] =>
    [ MacFJA\RediSearch\IndexBuilder noHighLight] =>
    [ MacFJA\RediSearch\IndexBuilder noFields] =>
    [ MacFJA\RediSearch\IndexBuilder noFrequencies] =>
    [ MacFJA\RediSearch\IndexBuilder skipInitialScan] =>
    [ MacFJA\RediSearch\IndexBuilder stopWords] =>
    [ MacFJA\RediSearch\IndexBuilder fields] => Array
        (
        )

)

Searching in next for salvation of this issue I found a hint that this could be raised as
redis doesn't have the RediSearch module loaded. How can I check it and fix it ?

also which parameters have I to use in line :

\Predis\Client(/* ... */)
Thank you!

@MacFJA
Copy link
Owner

MacFJA commented Feb 26, 2023

In order to use this library, you need to have a Redis server with the RediSearch module installed and enabled.


How can I check it [...] ?

To see if the module is enabled (and its version) you can run this command:

> MODULE LIST

or with redis-cli:

user@host:~$ redis-cli -h 127.0.0.1 MODULE LIST            
1) 1) "name"
   2) "ReJSON"
   3) "ver"
   4) (integer) 999999
2) 1) "name"
   2) "search"
   3) "ver"
   4) (integer) 20604

How can I [...} fix it ?

For the steps to install RediSearch (if needed), you can look here: https://redis.io/docs/stack/search/quick_start/


also which parameters have I to use in line :
\Predis\Client(/* ... */)

Here the official documentation on how to connect to a Redis server with Predis: https://github.com/predis/predis#connecting-to-redis
But to put it simply:

new \Predis\Client('redis://127.0.0.1:6379');
// Change the 127.0.0.1 to the IP of the Redis server if it's not on the same server as your PHP
// Change the 6379 to the port used by Redis (6379 is the default port of Redis)

@MacFJA MacFJA added the question Further information is requested label Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants