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

Add ability to clear all documents from a collection without dropping the collection and schema #28

Closed
shijithkjayan opened this issue Jun 26, 2024 · 5 comments · Fixed by #33
Assignees
Labels
enhancement New feature or request

Comments

@shijithkjayan
Copy link
Contributor

Hi,
I would like to request a feature to clear all documents from a collection without dropping the collection and its schema. This can be useful in scenarios where we want to reset the data in a collection but retain the schema for future use.

@shijithkjayan
Copy link
Contributor Author

cc: @njausteve

@jaeyson
Copy link
Owner

jaeyson commented Jun 26, 2024

Hi @shijithkjayan good idea. I'll circle back in couple of days and will let you know the progress. I'm replying here just to acknowledge the request. Thanks!

@jaeyson jaeyson self-assigned this Jun 26, 2024
@jaeyson jaeyson added the enhancement New feature or request label Jun 26, 2024
@jaeyson jaeyson moved this to Todo in ExTypesense Jun 26, 2024
@jaeyson
Copy link
Owner

jaeyson commented Jun 28, 2024

Hi @shijithkjayan. I'm not sure if you saw this thread: typesense/typesense#1613

TLDR on that thread:

An alternative could be to simply delete the collection and recreate it

This is indeed the workaround for now.

workaround

via docs

To delete multiple documents by ID, you can use filter_by=id: [id1, id2, id3].

To delete all documents in a collection, you can use a filter that matches all documents in your collection. For eg, if you have an int32 field called popularity in your documents, you can use filter_by=popularity:>0 to delete all documents. Or if you have a bool field called in_stock in your documents, you can use filter_by=in_stock:[true,false] to delete all documents.

I may have to update the Document module regarding this feature, since the docs gave us some idea how to match all documents in a collection leaving it up to developer's implementation.

What do you think?

@shijithkjayan
Copy link
Contributor Author

shijithkjayan commented Jun 28, 2024

Hi @jaeyson its indeed what I am doing right now. I drop a collection and then recreate it without any of the documents. I see that typesense itself doesn't support clearing an index and is suggesting a workaround. I am just wondering if you could add the logic for this in the library so those who use your library don't have to do it.

And yes, I like the idea of using a filter to delete multiple documents together. Would be great if you could incorporate that also.

@jaeyson jaeyson moved this from Todo to In Progress in ExTypesense Jun 28, 2024
@jaeyson jaeyson linked a pull request Jul 3, 2024 that will close this issue
@jaeyson
Copy link
Owner

jaeyson commented Jul 9, 2024

Hi @shijithkjayan kindly check this PR #33, specifically test/document_test.exs. Let me know your thoughts on this.

@github-project-automation github-project-automation bot moved this from In Progress to Done in ExTypesense Jul 13, 2024
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
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants