-
Notifications
You must be signed in to change notification settings - Fork 109
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
Fetch model from ID when filling results #55
Comments
Having the data fetched from the relational database will help with the consistency of the data however we might want to look at the drawbacks that this approach might cause. 1- at each search request we are calling both elasticsearch and rdb which is avoidable in the majority of the scenarios. 2- there are a lot of scenarios when you want to store a relationship value with the parent object in elastic search for instance a post tags. In those scenarios we won't be able eager load the relationships so we will face n+1 problem. 3- in a read only application where the data is stored by another application only in elasticsearch. In this case we won't be able to use the package because we will try to hit the rdb ! I think having something like that could help $result = Book::search()->match('title','foo')->get();
$resultFresh = $result->hits()->fresh()->with('tags','author')->get(); what do you think ? |
Those are good points. My thoughts:
Again, if you agree on these points, I'm more than happy to contribute a PR :) |
@hipsterjazzbo I think we are getting closer to a solution. The lazy-eager loading idea could solve a lot of performance issues when re-fetching the document from the DB. On the other side the performance difference can still be significant the Moreover, since we are going to hit the database another time why not give the user the ability to add additional query filters before executing the query? What are your concerns for the proposed API? As as side note the models dont break unless you try to persist so read-only is okey and convenient. I know a couple of projects where they use it as read only. Finally the most important thing is that in production most probably you will have ES clustered as opposed to MYSQL where you might have only one node. if you force retrieval from DB you are discarding all the benefits of having a cluster (Load, Speed, Max Requests Number ...). |
I still feel like it wouldn't be an issue, in terms of hitting db. It'd be one fast select statement. Also, the whole reason this came up is that my models are in fact broken — I customise the data I store in elastic for performance reasons. One of the things I don't store is a |
+1 for an option to fetch fresh values.. |
I've been thinking about this more. The core issue here is that I propose this:
This keeps the advantages of the current implementation, in that is stays fast, and doesn't force models to be selected, while also 1. making models available very easily if needed, and 2. not presenting models that don't actually relate to the database like they should. Thoughts, @sleimanx2? |
Further thoughts: Doing it this way also opens up the door for future, more advanced usage. For example: In additon to $model->newQueryWithoutScopes()->whereIn($model->getQualifiedKeyName(), $ids); Which could then be built on if needed. |
At the moment, if I specify only certain fields to be indexed (with
$searchable
for example), only those fields will be filled in search results.EloquentFiller::fill()
should re-retrieve the models from the DB fresh, and use those to populate the results.An example of such a modification:
The reason I haven't made this a PR is because I can see that
EloquentFiller
is doing a number of other things besides just spinning upModel
instances. If you could enumerate what else it's doing for me I am happy to do the work. I'm using this package quite extensively :)The text was updated successfully, but these errors were encountered: