This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-decanter.git


The following commit(s) were added to refs/heads/master by this push:
     new 57cc94e  [KARAF-5500] Upgrade jest appender to be compliant with 
elasticsearch 5 & 6
57cc94e is described below

commit 57cc94e9ab505c45c362156cbd352eaf805aed64
Author: Jean-Baptiste Onofré <jbono...@apache.org>
AuthorDate: Fri Feb 2 14:04:12 2018 +0100

    [KARAF-5500] Upgrade jest appender to be compliant with elasticsearch 5 & 6
---
 .../org.apache.karaf.decanter.appender.elasticsearch.jest.cfg    | 2 ++
 .../appender/elasticsearch/jest/ElasticsearchAppender.java       | 9 +++------
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git 
a/appender/elasticsearch-jest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.jest.cfg
 
b/appender/elasticsearch-jest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.jest.cfg
index d8b68aa..073b6f6 100644
--- 
a/appender/elasticsearch-jest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.jest.cfg
+++ 
b/appender/elasticsearch-jest/src/main/cfg/org.apache.karaf.decanter.appender.elasticsearch.jest.cfg
@@ -15,6 +15,8 @@ address=http://localhost:9200
 # index.prefix=karaf
 # If true, it creates an index per Decanter event day
 # index.event.timestamped=true
+# Index type
+# index.type=decanter
 
 # Marshaller to use (json is recommended)
 marshaller.target=(dataFormat=json)
\ No newline at end of file
diff --git 
a/appender/elasticsearch-jest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/jest/ElasticsearchAppender.java
 
b/appender/elasticsearch-jest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/jest/ElasticsearchAppender.java
index d0791f9..49174df 100644
--- 
a/appender/elasticsearch-jest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/jest/ElasticsearchAppender.java
+++ 
b/appender/elasticsearch-jest/src/main/java/org/apache/karaf/decanter/appender/elasticsearch/jest/ElasticsearchAppender.java
@@ -58,6 +58,7 @@ public class ElasticsearchAppender implements EventHandler {
     private JestClient client;
     private String indexPrefix;
     private boolean indexTimestamped;
+    private String indexType;
 
     private final SimpleDateFormat tsFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SSS'Z'");
     private final SimpleDateFormat indexDateFormat = new 
SimpleDateFormat("yyyy.MM.dd");
@@ -98,6 +99,7 @@ public class ElasticsearchAppender implements EventHandler {
 
         indexPrefix = getValue(config, "index.prefix", "karaf");
         indexTimestamped = Boolean.parseBoolean(getValue(config, 
"index.event.timestamped", "true"));
+        indexType = getValue(config, "index.type", "decanter");
     }
     
     private String getValue(Dictionary<String, Object> config, String key, 
String defaultValue) {
@@ -123,7 +125,7 @@ public class ElasticsearchAppender implements EventHandler {
         String indexName = getIndexName(indexPrefix, getDate(event));
         String jsonSt = marshaller.marshal(event);
 
-        JestResult result = client.execute(new 
Index.Builder(jsonSt).index(indexName).type(getType(event)).build());
+        JestResult result = client.execute(new 
Index.Builder(jsonSt).index(indexName).type(indexType).build());
 
         if (!result.isSucceeded()) {
             throw new IllegalStateException(result.getErrorMessage());
@@ -136,11 +138,6 @@ public class ElasticsearchAppender implements EventHandler 
{
         return date;
     }
 
-    private String getType(Event event) {
-        String type = (String)event.getProperty("type");
-        return type != null ? type : "karaf_event";
-    }
-
     private String getIndexName(String prefix, Date date) {
         if (indexTimestamped) {
             return prefix + "-" + indexDateFormat.format(date);

-- 
To stop receiving notification emails like this one, please contact
jbono...@apache.org.

Reply via email to