diff --git a/src/main/java/org/elasticsearch/river/hbase/HBaseRiver.java b/src/main/java/org/elasticsearch/river/hbase/HBaseRiver.java index 2355950..7c2d18d 100644 --- a/src/main/java/org/elasticsearch/river/hbase/HBaseRiver.java +++ b/src/main/java/org/elasticsearch/river/hbase/HBaseRiver.java @@ -113,6 +113,12 @@ public class HBaseRiver extends AbstractRiverComponent implements River, Uncaugh */ public final String columnSeparator; + /** + * Define a custom mapping that will be used instead of an automatically generated one. Make sure to enable time stamps + * and if you want an id-field to be recognized set the proper alias. + */ + public final String customMapping; + /** * Loads and verifies all the configuration needed to run this river. * @@ -140,6 +146,7 @@ public HBaseRiver(final RiverName riverName, final RiverSettings settings, final final String family = readConfig("family", null); this.family = family != null ? family.getBytes(this.charset) : null; this.qualifiers = readConfig("qualifiers", null); + this.customMapping = readConfig("customMapping", null); if (this.interval <= 0) { throw new IllegalArgumentException("The interval between runs must be at least 1 ms. The current config is set to " @@ -200,11 +207,16 @@ public synchronized void start() { this.logger.info("Starting HBase Stream"); String mapping; - if (this.idField == null) { - mapping = "{\"" + this.type + "\":{\"_timestamp\":{\"enabled\":true}}}"; + if (this.customMapping != null && !this.customMapping.trim().isEmpty()) { + mapping = this.customMapping; } else { - mapping = "{\"" + this.type + "\":{\"_timestamp\":{\"enabled\":true},\"_id\":{\"path\":\"" + this.idField + "\"}}}"; + if (this.idField == null) { + mapping = "{\"" + this.type + "\":{\"_timestamp\":{\"enabled\":true}}}"; + } + else { + mapping = "{\"" + this.type + "\":{\"_timestamp\":{\"enabled\":true},\"_id\":{\"path\":\"" + this.idField + "\"}}}"; + } } try {