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

Reloading Indexes on New Record Insertion in DB #90

Closed
blackode opened this issue Dec 15, 2020 · 4 comments
Closed

Reloading Indexes on New Record Insertion in DB #90

blackode opened this issue Dec 15, 2020 · 4 comments

Comments

@blackode
Copy link

Here, I'm building the indexes when the application starts using mix task

How can we reload the index as soon as a new record inserted into DB?
Do we have to stop application and rebuild the indexes here?

Glad if we have any automation here, unfortunately I did not find any other than tasks.

Thanks :)

@danielberkompas
Copy link
Owner

This package doesn't include any automatic way to do this. You would need to set up your code such that whenever you insert a record into the database, you make a MyCluster.post request to also insert that record into your index. You could use Ecto.Multi to do this.

@blackode
Copy link
Author

@danielberkompas
Thanks for the reply.
I saw a function named hot_swap/2 in module Elasticsearch.Index

So I thought to use in the following way...

Elasticsearch.Index.hot_swap(MyCluster, "posts")
# for whenever a post is added similaryly for the rest.

I still doubt using this way as for every new post it will create new index with prefix time.

Does this approach will have the impact in the code performance? If not we can use this instead of using Elasticsearch.post right?

FYI, we are using scylladb in our project.

Glad if you could confirm the approach.

Thank You :)

@danielberkompas
Copy link
Owner

I don't think you should use hot_swap for this. It's not necessary to create a new index every time you create a post. Use Elasticsearch.put_document instead: https://hexdocs.pm/elasticsearch/1.0.0/Elasticsearch.html#put_document/3

@blackode
Copy link
Author

blackode commented Dec 18, 2020

Thank you :) @danielberkompas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants