Reloading Indexes on New Record Insertion in DB
blackode opened this issue · 4 comments
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 :)
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.
@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 :)
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
Thank you :) @danielberkompas