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

Reindex with shared index #234

Open
jeremylynch opened this issue Jan 30, 2023 · 4 comments
Open

Reindex with shared index #234

jeremylynch opened this issue Jan 30, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@jeremylynch
Copy link

The project describes how to share a single index across multiple models. However, when calling reindex! as described, the index is cleared and replaced with the objects from only one of the two models.

Algoliasearch-rails has an option for atomical indexing, is it possible to achieve this in meiliesearch-rails also?

@brunoocasali brunoocasali added the enhancement New feature or request label Feb 2, 2023
@brunoocasali
Copy link
Member

Hey @jeremylynch how are you?

Unfortunately, it does not :/ But I agree that is a very good addition to the library. PRs are welcome!

@ellnix
Copy link
Collaborator

ellnix commented Sep 22, 2023

The project describes how to share a single index across multiple models. However, when calling reindex! as described, the index is cleared and replaced with the objects from only one of the two models.

I cannot reproduce this issue. Nowhere in the source does reindex! actually clear the index (it updates/deletes on a per document basis). Are you sure your primary keys are distinct? It could be that nothing is actually being cleared but simply written over.

Edit:
I also do not see how atomical indexing would fix this issue, I can only see how it would cause it. Please let me know if I'm wrong or misunderstood something, I am new to this project.

@brunoocasali
Copy link
Member

I cannot reproduce this issue. Nowhere in the source does reindex! actually clear the index (it updates/deletes on a per document basis). Are you sure your primary keys are distinct? It could be that nothing is actually being cleared but simply written over.

How did you try to reproduce @ellnix? Can you share some code 😇?

Talking more about the way we do the reindex:

I do like the idea of using a delete index and then starting to index the documents again. However, doing so will imply a service disruption for the users right away. So, I believe the initial implementation tried to create a behavior similar to swap_index.

@ellnix
Copy link
Collaborator

ellnix commented Oct 10, 2023

How did you try to reproduce @ellnix? Can you share some code 😇?

Unfortunately I don't think I can find the code since I just kept editing it. I create two models Book and BlogPost, added an Author index to both of them and no matter what I did, and no matter the order I did it in, #reindex! on Book would not erase BlogPost documents and vice versa.

The only time when calling #reindex on BlogPost removed Book documents from the index was when their primary keys were not distinct (blog post with id 0 would override book with id 0, etc...). However, this is not a supported use case and the README specifically mentions having distinct primary keys.

At the end of it I resorted to going through the relevant parts of the source code and trying the meilisearch-ruby methods myself on an irb session.

I do like the idea of using a delete index and then starting to index the documents again. However, doing so will imply a service disruption for the users right away. So, I believe the initial implementation tried to create a behavior similar to swap_index.

If I understand it correctly, it would run into the same problems that index-swap runs into: #267 (comment).

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

No branches or pull requests

3 participants