Skip to content

Add delete if exist method #107

@bidoubiwa

Description

@bidoubiwa

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 with swap, 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

client.index("myindex").deleteIfExist()
client.deleteIndexIfExists("myindex")

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.

client.index("myindex").delete({ ifExists: true })
client.deleteIndex("myindex", { ifExists: true })

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.

const deleteOccured = client.index('myindex').deleteIfExists() // true of 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:

const index = client.index('myindex').deleteIfExists()
index.addDocuments(myDocuments) 

Without this option we have to do this:

client.index('myindex').deleteIfExists()
client.index('myindex').addDocuments(myDocuments)

TODO

Metadata

Metadata

Assignees

No one assigned

    Labels

    SDKsRelated to the MeiliSearch SDKsissues available in reposThe related issues have been open in the concerned repositories

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions