Elasticquent
Elasticquent copied to clipboard
reindex() doesn't work properly
I have the such ElasticSearch index:
$teachers = UserModel::select(\DB::raw('users.id as user_id, null as child_name, users.name as name, users.info as info, users.role_id, subjects.name as subject_name, classes.name as class_name')) ->join('teacher_subjects', 'users.id', '=', 'teacher_subjects.teacher_id') ->join('subjects', 'subjects.id', '=', 'teacher_subjects.subject_id') ->join('classes', 'classes.id', '=', 'teacher_subjects.class_id') ->where('users.role_id', \Config::get('constants.ROLE_TEACHER'));
$students = UserModel::select(\DB::raw('users.id as user_id, null as child_name, users.name as name, users.info as info, users.role_id,
null as subject_name, classes.name as class_name'))
->join('student_classes', 'users.id', '=', 'student_classes.student_id')
->join('classes', 'classes.id', '=', 'student_classes.class_id')
->where('users.role_id', \Config::get('constants.ROLE_STUDENT'));
$users = UserModel::select(\DB::raw('users.id as user_id,
(select group_concat(name) from users u join student_parents on u.id = student_parents.student_id where student_parents.parent_id = users.id)
as child_name, name, info, role_id, null as subject_name, null as class_name'))
->union($teachers)
->union($students)
->where('users.role_id', \Config::get('constants.ROLE_PARENT'))
->havingRaw('child_name is not null')
->get();
$users->addToIndex();
This request adds to the index 19 items. After reindex() there are 82. The difference is that reindex() adds to the index all the data from the main table 'users' which depends on UserModel. Is it bug or I didn't set the index in UserModel properly?
Now I call deleting and re-adding the index instead of reindex(), but I don't like this solution. I think it will be too slow when the index will contain a lot of data...
Dumping a bunch of code, then asking why it does not work is not a proper use of a github issues. This is more suitable for stackoverflow Q&A. Would be best to create a small, easily replicatable and isolated example that we can work with.
We won't be debugging your code for you.
@Pashaster12