karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anierb...@apache.org
Subject karaf-decanter git commit: [KARAF-3569] - DECANTER: Index per day instead of index per document
Date Thu, 26 Feb 2015 10:28:14 GMT
Repository: karaf-decanter
Updated Branches:
  refs/heads/master ff34fdd9c -> d34bcf759


[KARAF-3569] - DECANTER: Index per day instead of index per document

Project: http://git-wip-us.apache.org/repos/asf/karaf-decanter/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-decanter/commit/d34bcf75
Tree: http://git-wip-us.apache.org/repos/asf/karaf-decanter/tree/d34bcf75
Diff: http://git-wip-us.apache.org/repos/asf/karaf-decanter/diff/d34bcf75

Branch: refs/heads/master
Commit: d34bcf7591ff3c350ec73b739491dea910121935
Parents: ff34fdd
Author: anierbeck <bcanhome@googlemail.com>
Authored: Thu Feb 26 11:27:40 2015 +0100
Committer: anierbeck <bcanhome@googlemail.com>
Committed: Thu Feb 26 11:27:40 2015 +0100

----------------------------------------------------------------------
 .../appender/elasticsearch/ElasticsearchAppender.java    | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/d34bcf75/appender/elasticsearch/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
----------------------------------------------------------------------
diff --git a/appender/elasticsearch/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
b/appender/elasticsearch/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
index 9e8754e..06e36d0 100644
--- a/appender/elasticsearch/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
+++ b/appender/elasticsearch/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/ElasticsearchAppender.java
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * Karaf Decanter appender which insert into Elasticsearch
@@ -36,7 +37,8 @@ public class ElasticsearchAppender implements Appender {
 
     private final static Logger LOGGER = LoggerFactory.getLogger(ElasticsearchAppender.class);
     
-    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+    private final SimpleDateFormat tsFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
     public void append(Map<Long, Map<String, Object>> data) throws Exception
{
         LOGGER.debug("Appending into Elasticsearch");
@@ -47,8 +49,11 @@ public class ElasticsearchAppender implements Appender {
             LOGGER.debug("Connecting to Elasticsearch instance located localhost:9300");
             Settings settings = ImmutableSettings.settingsBuilder().classLoader(Settings.class.getClassLoader()).build();
             client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("localhost",
9300));
-            for (Long unit : data.keySet()) {
-                client.prepareIndex("@timestamp", dateFormat.format(new Date(unit))).setSource(data.get(unit)).execute().actionGet();
+            for(Entry<Long, Map<String, Object>> entry : data.entrySet()){
+            	Date date = new Date(entry.getKey());
+            	entry.getValue().put("@timestamp", tsFormat.format(date));
+            	String indexName = String.format("karaf_%s", dateFormat.format(date));
+            	client.prepareIndex(indexName, "karaf_event").setSource(entry.getValue()).execute().actionGet();
             }
             LOGGER.debug("Apppending done");
         } catch (Exception e) {


Mime
View raw message