elasticquent / Elasticquent

Maps Laravel Eloquent models to Elasticsearch types
MIT License
1.35k stars 401 forks source link

Several indexes for one Eloquent Model #130

Open Pashaster12 opened 7 years ago

Pashaster12 commented 7 years ago

Is it possible to make two and many indexes for the one model? For example, I have the DB's table called 'users' where I store information about users with different roles (role_id). And I want to create different indexes for each user role (teachers, students, etc.). But the problem is I have one Laravel Eloquent Model for the table 'users'. What the best way for solution this problem? Make one index with unions different roles or make several indexes for each users' category? Thanks for reply.

thaoha commented 7 years ago

You should use type in your index. Each index can have many type.

Pashaster12 commented 7 years ago

@thaoha As for ElasticQuent docs, Eloquent Model may have one type too, which set with GetTypeName:

function getTypeName() { return 'custom_type_name'; }

As you see, there isn't an array in the returned value... So, how can I set different types for one Eloquent Model - the problem is the same as with several indexes for one model.

thaoha commented 7 years ago

Very easy @Pashaster12. With one table you can create many Model so with each model you can set with different type.

Pashaster12 commented 7 years ago

@thaoha Yeah, I understand this. But I don't like this way, because I should create a lot of fake models for additional indexes.

thaoha commented 7 years ago

Yeah, but personally I think you should create model for each type because it make your structure more clearly and you can have few logic for each type as you want.

Tom5om commented 6 years ago

Types are being removed, see: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html