How do i delete child docs in my parent-child relationship automatically in elasticsearch after a particular interval is finished

link: https://stackoverflow.com/q/57704269/11432290

Can someone help me with this as i wanted to delete my child docs in my parent child relationship as described above in the link. Your guidance will be highly appreciated.

Both Curator and ILM rely on deleting complete indices, so will not suit your use case as you will need to delete specific document from the index/indices. To do this you will need to use the delete-by-query API. You will however need to schedule this yourself as I do not think there is any suitable way to do that in Elasticsearch.

But i think that delete_by_query is a very expensive operation so will it be feasible to run it for millions of documents daily.

It is very expensive as each delete is an update behind the scenes. It is however the only way to delete select documents from an index, so I do not think you have much choice unless you can change your data model to flat documents in time-based indices, which are much more efficient to delete.

well i guess then, thier must be a way in parent-child relationship to delete all the child docs except for parent docs but I can't seem to find one.

As far as I know there is not, and even if it were it would still need to do it the same way delete-by-query works.

If you have time-based data, why are you using parent-child in the first place? Why not denormalize your data model?

thank you, for your help.

well the business use case is such that the parent child is according to my needs.

What are the requirements that drive this? Do you have parent documents that are very large or change frequently?

no the child docs are large and a parent can have 100's of child documents.

What is driving the use of parent-child relationship then? Query requirements?

yes it plays a big role as with a single query i am able to segment my users. Also i have to frequently update and insert docs so re-indexing is efficient here.

waiting for your reply sir....

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.