Author: markus
Date: Fri Jul 5 09:03:50 2013
New Revision: 1499952
URL: http://svn.apache.org/r1499952
Log:
NUTCH-1598 ElasticSearchIndexer to read ImmutableSettings from config
Added:
nutch/trunk/conf/elasticsearch.conf
Modified:
nutch/trunk/CHANGES.txt
nutch/trunk/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
Modified: nutch/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/nutch/trunk/CHANGES.txt?rev=1499952&r1=1499951&r2=1499952&view=diff
==============================================================================
--- nutch/trunk/CHANGES.txt (original)
+++ nutch/trunk/CHANGES.txt Fri Jul 5 09:03:50 2013
@@ -2,6 +2,8 @@ Nutch Change Log
Nutch Development Trunk
+* NUTCH-1598 ElasticSearchIndexer to read ImmutableSettings from config
(markus)
+
* NUTCH-1520 SegmentMerger looses records (markus)
* NUTCH-1602 improve the readability of metadata in readdb dump normal (lufeng)
Added: nutch/trunk/conf/elasticsearch.conf
URL:
http://svn.apache.org/viewvc/nutch/trunk/conf/elasticsearch.conf?rev=1499952&view=auto
==============================================================================
--- nutch/trunk/conf/elasticsearch.conf (added)
+++ nutch/trunk/conf/elasticsearch.conf Fri Jul 5 09:03:50 2013
@@ -0,0 +1,2 @@
+# Settings for Elasticsearch indexer plugin
+# Format: key=value\n
Modified:
nutch/trunk/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
URL:
http://svn.apache.org/viewvc/nutch/trunk/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java?rev=1499952&r1=1499951&r2=1499952&view=diff
==============================================================================
---
nutch/trunk/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
(original)
+++
nutch/trunk/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
Fri Jul 5 09:03:50 2013
@@ -23,6 +23,8 @@ import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
+import java.io.BufferedReader;
+import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
@@ -40,6 +42,7 @@ import org.elasticsearch.action.index.In
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.node.Node;
@@ -77,13 +80,32 @@ public class ElasticIndexWriter implemen
clusterName = job.get(ElasticConstants.CLUSTER);
host = job.get(ElasticConstants.HOST);
port = job.getInt(ElasticConstants.PORT, -1);
+
+ Builder settingsBuilder = ImmutableSettings.settingsBuilder();
+
+ BufferedReader reader = new
BufferedReader(job.getConfResourceAsReader("elasticsearch.conf"));
+ String line;
+ String parts[];
+
+ while ((line = reader.readLine()) != null) {
+ if (StringUtils.isNotBlank(line) && !line.startsWith("#")) {
+ line.trim();
+ parts = line.split("=");
+
+ if (parts.length == 2) {
+ settingsBuilder.put(parts[0].trim(), parts[1].trim());
+ }
+ }
+ }
+
+ // Set the cluster name and build the settings
+ Settings settings = settingsBuilder.put("cluster.name",
clusterName).build();
// Prefer TransportClient
if (host != null && port > 1) {
- Settings settings =
ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build();
client = new TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress(host, port));
} else if (clusterName != null) {
- node = nodeBuilder().clusterName(clusterName).client(true).node();
+ node = nodeBuilder().settings(settings).client(true).node();
client = node.client();
}