Skip to content

Commit

Permalink
- Added option to allow custom mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mallocator committed Apr 1, 2013
1 parent 24a2712 commit df908b0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/org/elasticsearch/river/hbase/HBaseRiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit df908b0

Please sign in to comment.