-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add delete if exist method #107
Comments
Hello! Not sure to get it! Can you detail the context in which you would use this method? |
for example on docs-scrapper. Before adding the new document you would typically delete the index before re-creating one add the settings and the documents. When updating databases I often go with the same solution, first delete if it existed, then add documents and settings. |
Oh you want to add the Ok, this would be a temporary solution because MeilISearch does not handle the swap index yet. We have to think if it's really worth taking time to add it to every SDK and then remove it before the release of the swap index. |
This is something I used a lot in different databases: POSTGRES/ MySQL/ most sql db's
Mongoreturns false but not an error when attempting to delete a collection that exists. ElasticsearchDelete a document if it exist {
"query": {
"exists": {
"field": "name"
}
}
}
Is this related to this issue https://github.com/meilisearch/transplant/issues/28 ? |
Yes 🙂 |
The swap is great, but I think nonetheless user may still want that method for tests/security/shutdown. It would avoid that in our e2e tests we have to delete all indexes before running the tests (at least in javascript SDK). |
The winner is: client.index("myindex").deleteIfExist()
client.deleteIndexIfExists("myindex") I pass it as |
I have this ready for the Python client, but have one question. Do you want the methods to return anything? |
It could return Extract : So now that there's no longer an artists collection in our database, let's try to drop it and see what message we get:
Resulting message:
It returned false because the collection doesn't exist. |
I came across what I think could be an issue with this variant index = client.index('myindex')
index.addDocuments(myDocuments) However this is an issue with index = client.index('myindex').deleteIfExists()
index.addDocuments(myDocuments) // Can't do this because this isn't and Index object The motivation behind adding this is so the index can be removed before doing more work with the index so I don't think you would want to do this as it seems redundant correct? client.index('myindex').deleteIfExists()
index = client.index('myindex')
index.addDocuments(myDocuments) If you all think this is an issue I think it would apply to all SDKs. One possible solution is index = client.index('myindex').deleteIfExists()
index.addDocuments(myDocuments) // Now this works because deleteIfExists() returned an instance of Index Or maybe most people would do it like this anyways so this isn't an issue at all? client.index('myindex').deleteIfExists()
client.index('myindex').addDocuments(myDocuments)
|
It is a very interesting suggestion. Nonetheless, since most of our methods do not return an instance of index, we are not really into a chainable-method strategy (not sure if that's the term tell me if it's not clear). I guess in such a strategy we would be able to do things like (the client
.index('myindex')
.deleteIfExists()
.addDocuments(data, { waitFor: true })
.updateSettings(settings, { waitFor: true }) Today I think only, get, update and create index methods returns an instance. But it raises a very interesting question as I didn't thought about having chainable methods. |
Yes, as far as I am aware if |
I think |
I know for sure |
Hello @sanders41, we agreed that returning true/false is the best solution. A few other arguments have been raised:
So we stay with the idea that if something was deleted we return true, if not, we return false |
268: Adding delete if exists methods r=alallema a=sanders41 Relates to meilisearch/integration-guides#107 Co-authored-by: Paul Sanders <psanders1@gmail.com>
142: Adding delete_index_if_exists method r=curquiza a=sanders41 Relates to meilisearch/integration-guides#107 Co-authored-by: Paul Sanders <psanders1@gmail.com>
918: Adding delete if exists methods r=bidoubiwa a=sanders41 Relates to meilisearch/integration-guides#107 Co-authored-by: Paul Sanders <psanders1@gmail.com>
The issues are opened in the concerned repositories |
According to #157 (comment), we decided to remove this method from the SDKs. I'm closing this issue RIP deleteIfExists 😢 |
State of deleting
As for now, to delete an index, one should first be sure the index does not exist already.
Problem
Re-indexing all documents is often slower than deleting the index, and push the documents on a fresh index.
Meaning that this is an operation that is potentially often used by our users (me for example)
Other Motivations
In
milli
we will be introduced withswap
, meilisearch/transplant#28 (see @curquiza response).Nontheless:
The swap is great, but nonetheless user may still want that method for tests/security/shutdown. It would avoid that in our e2e tests we have to delete all indexes before running the tests (at least in javascript SDK).
It can be used in a teardown method or a onstart as it cleans the instance.
It would avoid having
home-made
deleteIfExists function in our code that is not tested.Solution and Vote
We agreed on the necessity of this function. We still have to agree on a naming.
Examples are done using javascript
All in function name 👀
We provide a new function with an explicit naming
Pros
No need to search into references to know available parameters.
Only need to see available functions.
Cons
How longer the method name, how unreadable it becomes.
Optionnal parameter 🎉
We provide a new option object to already existing functions.
Pros
No need to create a new function, also more readable.
Cons
Need to know the existence of the options object and which options are available
Return value.
Boolean
If there was a delete, it would return true. If the index did not exist, and thus none have been deleted, it would return false.
Index instance
the method would return the instance in itself to let the user chain its actions without having to create a new index object.
Example:
Without this option we have to do this:
TODO
The text was updated successfully, but these errors were encountered: