forked from elastic/elasticsearch-river-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndexConfig.java
66 lines (55 loc) · 2.53 KB
/
IndexConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.elasticsearch.river.couchdb;
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeIntegerValue;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.river.RiverSettings;
import java.util.Map;
public class IndexConfig {
public static final String INDEX = "index";
public static final String NAME = "index";
public static final String TYPE = "type";
public static final String THROTTLE_SIZE = "throttle_size";
public static final String BULK_TIMEOUT = "bulk_timeout";
public static final String BULK_SIZE = "bulk_size";
static final TimeValue DEFAULT_BULK_TIMEOUT = timeValueMillis(10);
static final int DEFAULT_BULK_SIZE = 100;
static final int DEFAULT_THROTTLE_SIZE = 5 * DEFAULT_BULK_SIZE;
static final String DEFAULT_INDEX_NAME = "db";
private String name = DEFAULT_INDEX_NAME;
private String type = DEFAULT_INDEX_NAME;
private int bulkSize = DEFAULT_BULK_SIZE;
private TimeValue bulkTimeout = DEFAULT_BULK_TIMEOUT;
private int throttleSize = DEFAULT_THROTTLE_SIZE;
public static IndexConfig fromRiverSettings(RiverSettings riverSettings) {
IndexConfig cfg = new IndexConfig();
if (riverSettings.settings().containsKey(INDEX)) {
@SuppressWarnings("unchecked")
Map<String, Object> indexSettings = (Map<String, Object>) riverSettings.settings().get(INDEX);
cfg.name = nodeStringValue(indexSettings.get(NAME), DEFAULT_INDEX_NAME);
cfg.type = nodeStringValue(indexSettings.get(TYPE), DEFAULT_INDEX_NAME);
cfg.bulkSize = nodeIntegerValue(indexSettings.get(BULK_SIZE), DEFAULT_BULK_SIZE);
if (indexSettings.containsKey(BULK_TIMEOUT)) {
cfg.bulkTimeout = parseTimeValue(nodeStringValue(indexSettings.get(BULK_TIMEOUT), null), DEFAULT_BULK_TIMEOUT);
}
cfg.throttleSize = nodeIntegerValue(indexSettings.get(THROTTLE_SIZE), DEFAULT_THROTTLE_SIZE);
}
return cfg;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public int getBulkSize() {
return bulkSize;
}
public TimeValue getBulkTimeout() {
return bulkTimeout;
}
public int getThrottleSize() {
return throttleSize;
}
}