Closed itmeicn closed 2 years ago
Hello,
Your issue is that by default the IndexBuilder
consider that the RediSearch version is 2.0.0
. But JSON schema only exist in RediSearch 2.2.0
.
You can pass the version of RediSearch as the second parameter of the create
method:
$builder = new \MacFJA\RediSearch\IndexBuilder();
$res = $builder->setIndex($this->name . 'Idx')->setStructure('JSON')->addPrefixes($this->name . ':')
->setDefaultLanguage('chinese')
->addJSONTagField('id', 'id', null, true)
->addJSONTextField('userid', 'userid', false, 10, null, true)
->create($this->clientPhprearch, '2.2.0');
or
$builder=new \MacFJA\RediSearch\IndexBuilder();
$res=$builder->setIndex($this->name . 'Idx')->setStructure('JSON')->addPrefixes($this->name . ':')
->setDefaultLanguage('chinese')
->addJSONTagField('id', 'id', null, true)
->addJSONTextField('userid', 'userid', false, 10, null, true)
->create($this->clientPhprearch, \MacFJA\RediSearch\Redis\Initializer::getRediSearchVersion($this->clientPhprearch));
$builder=new \MacFJA\RediSearch\IndexBuilder();
$res=$builder->setIndex($this->name.'Idx')->setStructure('JSON')->addPrefixes($this->name.':')
->setDefaultLanguage('chinese')
->addJSONNumericField('$.id','id',true)
->addJSONTextField('$.userid','userid',false,10,null,true)
->addJSONTextField('$.username','username',false,8,null,true)
->addJSONNumericField('$.status','status',true)
->addJSONTextField('$.login_ip','login_ip')
->addJSONNumericField('$.login_time','login_time')
->addJSONTextField('$.token','token',false,6)
->addJSONTextField('$.mobile','mobile')
->addJSONTextField('$.create_time','create_time',false,null,null,true)
->addJSONTextField('$.coid','coid',false,null,null,true)
->addJSONTextField('$.shortcode','shortcode',false,4,null,true)
->addJSONTextField('$.pushid','pushid')
->addJSONNumericField('$.','kaoqin_remaind')
->addJSONTextField('$.telephone_number','telephone_number')
->addJSONNumericField('$.main_depart','main_depart',true)
->create($this->clientPhprearch,\MacFJA\RediSearch\Redis\Initializer::getRediSearchVersion($this->clientPhprearch));
Maybe add "$." to the field to execute correctly
Yes, I forgot to indicate this.
The first parameter of addJSON*
methods, must be valid JSON Path
ths
Maybe the good idea is to add this to the examples in the documentation... I've also been struggling with that issue for the last 24h :-/
Otherwise, thank you for this fantastic library. Everything else works very well!
is error: Missing command option: fields