/** * create a elasticsearch node client (embedded elasticsearch) * @param settings */ public ElasticsearchClient(final Settings.Builder settings) { // create a node this.elasticsearchNode = NodeBuilder.nodeBuilder().local(false).settings(settings).node(); // create a client this.elasticsearchClient = elasticsearchNode.client(); }
public PluginConfigurableNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) { super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins); } }
@Override public Connection connect(Configuration config) throws IOException { log.debug("Configuring Node Client"); ImmutableSettings.Builder settingsBuilder = settingsBuilder(config); if (config.has(ElasticSearchIndex.TTL_INTERVAL)) { String k = "indices.ttl.interval"; settingsBuilder.put(k, config.get(ElasticSearchIndex.TTL_INTERVAL)); log.debug("Set {}: {}", k, config.get(ElasticSearchIndex.TTL_INTERVAL)); } makeLocalDirsIfNecessary(settingsBuilder, config); NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build()); // Apply explicit Titan properties file overrides (otherwise conf-file or ES defaults apply) if (config.has(ElasticSearchIndex.CLIENT_ONLY)) { boolean clientOnly = config.get(ElasticSearchIndex.CLIENT_ONLY); nodeBuilder.client(clientOnly).data(!clientOnly); } if (config.has(ElasticSearchIndex.LOCAL_MODE)) nodeBuilder.local(config.get(ElasticSearchIndex.LOCAL_MODE)); if (config.has(ElasticSearchIndex.LOAD_DEFAULT_NODE_SETTINGS)) nodeBuilder.loadConfigSettings(config.get(ElasticSearchIndex.LOAD_DEFAULT_NODE_SETTINGS)); Node node = nodeBuilder.node(); Client client = node.client(); return new Connection(node, client); } };
private void openLocalDiscoveryClient() { logger.info("Using ElasticSearch AutoDiscovery mode"); Node node = NodeBuilder.nodeBuilder().client(true).local(true).node(); if (client != null) { client.close(); } client = node.client(); }
/** * Starts an ElasticSearch node. * @return the started node. */ public static Node startEsNode() { Node node = NodeBuilder.nodeBuilder().data(true).settings( Settings.settingsBuilder() .put(ClusterName.SETTING, EsConstants.CLUSTER_NAME) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(EsExecutors.PROCESSORS, 1) .put("http.enabled", true) .put("index.percolator.map_unmapped_fields_as_string", true) .put("index.store.type", "mmapfs") .put("path.home", "./data") ).build(); node.start(); return node; }
Node node = nodeBuilder().clusterName("yourcluster").client(true).node(); Client client = node.client();
/** * Close the connection to the remote elasticsearch client. This should only be called when the application is * terminated. * Please avoid to open and close the ElasticsearchClient for the same cluster and index more than once. * To avoid that this method is called more than once, the elasticsearch_client object is set to null * as soon this was called the first time. This is needed because the finalize method calls this * method as well. */ public void close() { if (this.elasticsearchClient != null) { this.elasticsearchClient.close(); this.elasticsearchClient = null; } if (this.elasticsearchNode != null) { this.elasticsearchNode.close(); this.elasticsearchNode = null; } }
@SafeVarargs public PluginAwareNode(boolean masterEligible, final Settings preparedSettings, final Class<? extends Plugin>... plugins) { super(InternalSettingsPreparer.prepareEnvironment(checkAndAddNodeName(preparedSettings), null), Arrays.asList(plugins), true); this.masterEligible = masterEligible; }
private String getPort() { return instance.settings().get("http.port"); }
public Client nodeClient() { return esNodes.get(0).client(); }
public EsClient client() { return new EsClient(SHARED_NODE.client()); }
private static void closeNode(Node node) { try { LoggerContext context = (LoggerContext) LogManager.getContext(false); Configurator.shutdown(context); node.close(); Thread.sleep(250); } catch (Throwable e) { //ignore } }
public ElasticsearchNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) { super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins); } }
public TestNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) { super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins); } }
public TestNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) { super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins); } }