import org.apache.commons.io.FileUtils;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.client.Client;
+import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.slf4j.Slf4jESLoggerFactory;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
import org.picocontainer.Startable;
private final String healthTimeout;
// available only after startup
- private Node node;
+ private Client client;
public ESNode(ServerFileSystem fileSystem, Settings settings) {
this(fileSystem, settings, DEFAULT_HEALTH_TIMEOUT);
.put("script.default_lang", "native")
.put("script.native." + ListUpdate.NAME + ".type", UpdateListScriptFactory.class.getName());
- switch (type) {
- case MEMORY:
+ initAnalysis(esSettings);
+
+
+ if (IndexProperties.ES_TYPE.TRANSPORT.equals(type)) {
+ client = new TransportClient(esSettings)
+ .addTransportAddress(new InetSocketTransportAddress("localhost",
+ settings.getInt(IndexProperties.NODE_PORT)));
+ } else {
+ if (IndexProperties.ES_TYPE.MEMORY.equals(type)) {
initMemoryES(esSettings);
- break;
- case TRANSPORT:
- initTransportES(esSettings);
- break;
- case DATA:
- default:
+ } else if (IndexProperties.ES_TYPE.DATA.equals(type)) {
initDataES(esSettings);
- break;
- }
+ }
+ initDirs(esSettings);
+ initRestConsole(esSettings);
+ initNetwork(esSettings);
- initAnalysis(esSettings);
- initDirs(esSettings);
- initRestConsole(esSettings);
- initNetwork(esSettings);
+ Node node = NodeBuilder.nodeBuilder()
+ .settings(esSettings)
+ .node();
+ node.start();
- node = NodeBuilder.nodeBuilder()
- .settings(esSettings)
- .node();
- node.start();
+ client = node.client();
+ }
- if (node.client().admin().cluster().prepareHealth()
+ if (client.admin().cluster().prepareHealth()
.setWaitForYellowStatus()
.setTimeout(healthTimeout)
.get()
}
private void addIndexTemplates() {
- node.client().admin().indices()
+ client.admin().indices()
.preparePutTemplate("default")
.setTemplate("*")
.addMapping("_default_", "{\"dynamic\": \"strict\"}")
esSettings
.put("index.mapper.dynamic", false)
- // Sortable text analyzer
+ // Sortable text analyzer
.put("index.analysis.analyzer.sortable.type", "custom")
.put("index.analysis.analyzer.sortable.tokenizer", "keyword")
.putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase", "truncate")
- // Edge NGram index-analyzer
+ // Edge NGram index-analyzer
.put("index.analysis.analyzer.index_grams.type", "custom")
.put("index.analysis.analyzer.index_grams.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter")
- // Edge NGram search-analyzer
+ // Edge NGram search-analyzer
.put("index.analysis.analyzer.search_grams.type", "custom")
.put("index.analysis.analyzer.search_grams.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase")
- // Word index-analyzer
+ // Word index-analyzer
.put("index.analysis.analyzer.index_words.type", "custom")
.put("index.analysis.analyzer.index_words.tokenizer", "standard")
.putArray("index.analysis.analyzer.index_words.filter",
"standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem")
- // Word search-analyzer
+ // Word search-analyzer
.put("index.analysis.analyzer.search_words.type", "custom")
.put("index.analysis.analyzer.search_words.tokenizer", "standard")
.putArray("index.analysis.analyzer.search_words.filter",
"standard", "lowercase", "stop", "asciifolding", "porter_stem")
- // Edge NGram filter
+ // Edge NGram filter
.put("index.analysis.filter.gram_filter.type", "edgeNGram")
.put("index.analysis.filter.gram_filter.min_gram", 2)
.put("index.analysis.filter.gram_filter.max_gram", 15)
.putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol")
- // Word filter
+ // Word filter
.put("index.analysis.filter.word_filter.type", "word_delimiter")
.put("index.analysis.filter.word_filter.generate_word_parts", true)
.put("index.analysis.filter.word_filter.catenate_words", true)
.put("index.analysis.filter.word_filter.split_on_numerics", true)
.put("index.analysis.filter.word_filter.stem_english_possessive", true)
- // Path Analyzer
+ // Path Analyzer
.put("index.analysis.analyzer.path_analyzer.type", "custom")
.put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy");
@Override
public void stop() {
- if (node != null) {
- node.close();
- node = null;
+ if (client != null) {
+ client.close();
+ client = null;
}
}
public Client client() {
- if (node == null) {
+ if (client == null) {
throw new IllegalStateException("Elasticsearch is not started");
}
- return node.client();
+ return client;
}
}