An explanation of the Trimmer feature in the Cluster dashboard.
Last updated
July 7, 2023

Bonsai offers support for automatically removing old indices from your cluster to save space. If you’re using Bonsai to host logs or some application that creates regular indices following a time-series naming convention, then you can specify one or more prefix patterns and Bonsai will automatically purge the oldest indices that match each pattern. The pattern will only match from the start of the index name.

This feature is found in the Cluster dashboard, under the Trimmer section:

For example, assume you’re indexing time-series data, say, number of support tickets in a day. You’re putting these in time-series indices like "support_tickets-201801010000", "support_tickets-201801020000", and so on.

With this feature, you could specify a pattern like "support_tickets-", and we’ll auto-prune the oldest indices first when you reach the size limit specified for the pattern. Indices scheduled for removal will be highlighted in red.

Please note we will not purge the last remaining index that matches the pattern, even if the size is above the limit.

Note on Trimmer and deleting documents

The trimmer feature only allows you to delete whole indexes and only if there are more than one with the same trimmer pattern. The trimmer does not delete just certain documents in an index. To remove a number of documents in an index your best option is to use delete_by_query.

Here is an example for deleting the 50 oldest documents, according to a hypothetical "date" field:

<div class="code-snippet w-richtext"><pre><code fs-codehighlight-element="code" class="hljs language-javascript">POST //_delete_by_query?conflicts=proceed

 "query": {
   "match_all": {}
 "sort": {
   "_script": {
     "type": "date",
     "order": "asc"    }
 "size": 50

The Elasticsearch Search API can be used to identify documents to delete. Please use your Console (or an equivalent tool) and build your query using the Search API first, and verify that you will only be deleting the documents you want. Do this before running the delete_by_query call against your query.

View code snippet
Close code snippet