Camel-Elasticsearch: create timestamped indices

One nice feature of the logstash-elasticsearch integration is that, by default, logstash will use timestamped indices
when feeding data to elastisearch.

This means that yesterday’s data is in a separate index from today’s data and from each other day’s data, simplifying index management. For instance, suppose you only want to keep the last 30 days:

elasticsearch-remove-old-indices.sh
-i 30

The Apache Camel Elasticsearch
component provides no such feature, but luckily it is quite easy to implement (when you know what to do. /grin
).

It is enough to define the proper header in the message and the elastisearch component will then use that header as the index name. Unfortunately this is not documented anywhere, but it can be understood seen in the source
. Once again, use the source, Luke.

So, let’s suppose the route is something as simple as:

            
            
        

Then all that is needed to is to define a content enricher bean as follows:

            
            
            
        

The bean is also pretty simple (imports omitted for brevity):

public class ESHeaders {
public void process(Exchange exchange) {
        Message in = exchange.getIn();
        DateFormat df=new SimpleDateFormat("YYYY.MM.dd");
        in.setHeader(ElasticsearchConfiguration.PARAM_INDEX_NAME, "mirth2-"+df.format(new Date()));
    }
}
稿源:unicolet.org (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合技术 » Camel-Elasticsearch: create timestamped indices

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录