haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Feature to delete documents after expiry in Elastic Search Document Store.

Open monika1800 opened this issue 5 years ago • 6 comments

Is your feature request related to a problem? Please describe. Is there a way during indexing we can index the set_expiry date and Elastic Search document store handles the deletion of these documents after the expiry?

Describe the solution you'd like If not, can such a feature be added in the elastic search document store where we can define the expiry date column during indexing the data and internally Elastic Search Doc store handles the deletion based on the expiry date.

monika1800 avatar Jun 25 '21 05:06 monika1800

Hey @monika1800,

Such an expiration schedule is currently not supported in Haystack. We are open for community contributions here, but I am wondering what equivalent you have in mind on the plain elasticsearch side. There was something like _ttl in earlier versions but it seems deprecated and replaced by something else (https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html).

As for now, maybe this workflow would work as well: at indexing time you provide a meta field expires_at="2020-07-20" or created_at=2020-07-06. You could then run daily jobs to delete all documents that have certain tags document_store.delete_documents(filters={"expires_at":"2020-07-20"}). While the filtering here currently only supports strings, we will soon extend this to dateranges (e.g. >= 2020-07-20)

tholor avatar Jul 06 '21 13:07 tholor

Hi @tholor ,

One of the approach I could think of using Elastic Search is -

In Elastic Search there is a delete_by_query API available which performs a deletion on every document that matches a query.

It also have range queries, where a date range can be provided to query some data.

If we just combine these both, then we can create a query which can delete the documents if it matches the date range search.

For e.g.

POST twitter/_delete_by_query { "query": { "range" : { "timestamp" : { "gte": "2015-01-01 00:00:00", "lte": "now", "time_zone": "+01:00" } } } }

Though @tholor, I am not sure how we can configure a field as a datetime field while creating the schema of an index in Elastic Search using haystack parameters.

Any pointers on this ?

monika1800 avatar Jul 06 '21 14:07 monika1800

This will be possible when we extend the capabilities of filters in haystack. We already have an issue for this, but haven't found the time to work on it yet (https://github.com/deepset-ai/haystack/issues/625).

The idea is to support range queries on dates (and much more). Once we have this, we can use something like document_store.delete_documents(filters={"expires_at":{"gte":"2020-07-20"}}).

tholor avatar Jul 08 '21 07:07 tholor

@tholor have you added this filter feature?

Omarnabk avatar Dec 31 '21 23:12 Omarnabk

@Omarnabk No, it's not implemented yet. We will kick off the required work soon (see #1958) to extend metadata types (incl. dates) and provide a more powerful syntax that will allow similar filter queries as above.

tholor avatar Jan 05 '22 13:01 tholor

We decided to not implement this feature, as it's easy to do outside of the document store by using its api. Closing for now.

ZanSara avatar Mar 15 '23 10:03 ZanSara