當前位置: 首頁>>代碼示例>>Java>>正文


Java Node.client方法代碼示例

本文整理匯總了Java中org.elasticsearch.node.Node.client方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.client方法的具體用法?Java Node.client怎麽用?Java Node.client使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.node.Node的用法示例。


在下文中一共展示了Node.client方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: EmbeddedElasticsearchServer

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
public EmbeddedElasticsearchServer(String storagePath) {
    this.storagePath = storagePath;
    try {
        tempFile = File.createTempFile("elasticsearch", "test");
        this.storagePath = tempFile.getParent();
        tempFile.deleteOnExit();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Settings.Builder elasticsearchSettings = Settings.builder()
            .put("http.enabled", "false")
            .put("path.data", this.storagePath)
            .put("path.home", System.getProperty("user.dir"))
            .put("transport.type", "local");

    node = new Node(elasticsearchSettings.build());
    client = node.client();
}
 
開發者ID:rfoltyns,項目名稱:log4j2-elasticsearch,代碼行數:20,代碼來源:BulkProcessorObjectFactoryTest.java

示例2: main

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
public static void main(String[] args)
{
	Node node = nodeBuilder().node();
	Client client = node.client();

	AdminClient ac = client.admin();

	client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
	ElasticTest t = new ElasticTest();
	t.initRiver(client);
	// t.initRiver(client);
	// t.getContributionsByCandName(client, "aaew_corpus_aaew_full", 0);
	t.search(client);
	// // on shutdown
	// // Configuration
	// ClientConfig clientConfig = new
	// ClientConfig.Builder("http://localhost:9200").multiThreaded(true).build();
	//
	// // Construct a new Jest client according to configuration via factory
	// JestClientFactory factory = new JestClientFactory();
	// factory.setClientConfig(clientConfig);
	// JestClient clientj = factory.getObject();
	// clientj.
	node.close();

}
 
開發者ID:cplutte,項目名稱:bts,代碼行數:27,代碼來源:ElasticTest.java

示例3: setup

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
@Override
public ClientWrapper setup() throws Exception {
    final Settings settings = Settings
        .builder()
        .put("node.name", InetAddress.getLocalHost().getHostName())
        .putArray("discovery.zen.ping.unicast.hosts", seeds)
        .put("cluster.name", clusterName)
        .put("node.data", false)
        .build();

    final Node node = new Node(settings);

    return new ClientWrapper(node.client(), new Runnable() {
        @Override
        public void run() {
            try {
                node.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
開發者ID:spotify,項目名稱:heroic,代碼行數:24,代碼來源:NodeClientSetup.java

示例4: getClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
public static Client getClient(Map stormConf, String boltType) {
    String host = ConfUtils.getString(stormConf, "es." + boltType
            + ".hostname", "localhost");

    Client client;

    // connection to ES
    if (host.equalsIgnoreCase("localhost")) {
        Node node = org.elasticsearch.node.NodeBuilder.nodeBuilder()
                .clusterName("elasticsearch").client(true).node();
        client = node.client();
    } else {
        Settings settings = ImmutableSettings.settingsBuilder()
                .put("cluster.name", "elasticsearch").build();
        client = new TransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(host,
                        9300));
    }
    return client;
}
 
開發者ID:zaizi,項目名稱:alfresco-apache-storm-demo,代碼行數:21,代碼來源:ElasticSearchConnection.java

示例5: startLocalNode

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
private ElasticClient startLocalNode(String clusterName, boolean refresh, int version) {
    final ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
            .put("node.name", applicationName + "-local-node" + System.currentTimeMillis()).put("node.data", true)
            .put("cluster.name", clusterName).put("index.store.type", "memory")
            .put("index.store.fs.memory.enabled", "true").put("gateway.type", "none")
            .put("path.data", "./local-cluster/" + clusterName + "/data")
            .put("path.work", "./local-cluster/" + clusterName + "/work")
            .put("path.logs", "./local-cluster/" + clusterName + "/logs").put("index.number_of_shards", "1")
            .put("index.number_of_replicas", "0").put("cluster.routing.schedule", "50ms");
    final Node localNode = NodeBuilder.nodeBuilder().settings(builder).node();

    final Client client = localNode.client();
    client.admin().cluster().prepareHealth().setWaitForYellowStatus().setTimeout(TimeValue.timeValueMinutes(1))
            .execute().actionGet();
    return new ElasticClient(client, applicationName, refresh, version);
}
 
開發者ID:ezbake,項目名稱:ezelastic,代碼行數:17,代碼來源:EzElasticHandler.java

示例6: buildNode

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
public Node buildNode(String id, Settings settings) {
    String settingsSource = getClass().getName().replace('.', '/') + ".yml";
    Settings finalSettings = settingsBuilder()
            .loadFromClasspath(settingsSource)
            .put(defaultSettings)
            .put(settings)
            .put("name", id)
            .build();
    if (finalSettings.get("gateway.type") == null) {
        finalSettings = settingsBuilder().put(finalSettings).put("gateway.type", "none").build();
    }
    if (finalSettings.get("cluster.routing.schedule") != null) {
        finalSettings = settingsBuilder().put(finalSettings).put("cluster.routing.schedule", "50ms").build();
    }
    Node node = nodeBuilder().settings(finalSettings).build();
    Client client = node.client();
    nodes.put(id, node);
    clients.put(id, client);
    return node;
}
 
開發者ID:jprante,項目名稱:elasticsearch-gatherer,代碼行數:21,代碼來源:AbstractNodeTest.java

示例7: openLocalDiscoveryClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
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();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:9,代碼來源:ElasticSearchTransportClient.java

示例8: makeClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
/**
 * Generates a TransportClient or NodeClient
 *
 * @param props a populated {@link java.util.Properties} object
 * @return a constructed {@link org.elasticsearch.client.Client}
 * @throws IOException if there is an error building the
 *                     {@link org.elasticsearch.client.Client}
 */
protected Client makeClient(Properties props) throws IOException {
  String clusterName = props.getProperty(MudrodConstants.ES_CLUSTER);
  String hostsString = props.getProperty(MudrodConstants.ES_UNICAST_HOSTS);
  String[] hosts = hostsString.split(",");
  String portStr = props.getProperty(MudrodConstants.ES_TRANSPORT_TCP_PORT);
  int port = Integer.parseInt(portStr);

  Settings.Builder settingsBuilder = Settings.builder();

  // Set the cluster name and build the settings
  if (!clusterName.isEmpty())
    settingsBuilder.put("cluster.name", clusterName);

  settingsBuilder.put("http.type", "netty3");
  settingsBuilder.put("transport.type", "netty3");

  Settings settings = settingsBuilder.build();

  Client client = null;

  // Prefer TransportClient
  if (hosts != null && port > 1) {
    TransportClient transportClient = new ESTransportClient(settings);
    for (String host : hosts)
      transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
    client = transportClient;
  } else if (clusterName != null) {
    node = new Node(settings);
    client = node.client();
  }

  return client;
}
 
開發者ID:apache,項目名稱:incubator-sdap-mudrod,代碼行數:42,代碼來源:ESDriver.java

示例9: createNodeClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
private Client createNodeClient() throws Exception {
	Settings.Builder settings = Settings.settingsBuilder();
	for (Map.Entry<String, String> entry : DEFAULTS.entrySet()) {
		if (!this.properties.getProperties().containsKey(entry.getKey())) {
			settings.put(entry.getKey(), entry.getValue());
		}
	}
	settings.put(this.properties.getProperties());
	Node node = new NodeBuilder().settings(settings)
			.clusterName(this.properties.getClusterName()).node();
	this.releasable = node;
	return node.client();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:14,代碼來源:ElasticsearchAutoConfiguration.java

示例10: testNullTransportClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void testNullTransportClient() throws Exception {

File dataDir = tempFolder.newFolder();

Node node = NodeBuilder.nodeBuilder()
	.settings(Settings.settingsBuilder()
		.put("path.home", dataDir.getParent())
		.put("http.enabled", false)
		.put("path.data", dataDir.getAbsolutePath()))
	// set a custom cluster name to verify that user config works correctly
	.clusterName("my-transport-client-cluster")
	.node();

final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

DataStreamSource<Tuple2<Integer, String>> source = env.addSource(new TestSourceFunction());

Map<String, String> config = new HashMap<>();
// This instructs the sink to emit after every element, otherwise they would be buffered
config.put(ElasticsearchSink.CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS, "1");
config.put("cluster.name", "my-transport-client-cluster");

source.addSink(new ElasticsearchSink<>(config, null, new TestElasticsearchSinkFunction()));

env.execute("Elasticsearch TransportClient Test");

// verify the results
Client client = node.client();
for (int i = 0; i < NUM_ELEMENTS; i++) {
 GetResponse response = client.get(new GetRequest("my-index",
	 "my-type", Integer.toString(i))).actionGet();
 Assert.assertEquals("message #" + i, response.getSource().get("data"));
}

node.close();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:38,代碼來源:ElasticsearchSinkITCase.java

示例11: testEmptyTransportClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void testEmptyTransportClient() throws Exception {

File dataDir = tempFolder.newFolder();

Node node = NodeBuilder.nodeBuilder()
	.settings(Settings.settingsBuilder()
		.put("path.home", dataDir.getParent())
		.put("http.enabled", false)
		.put("path.data", dataDir.getAbsolutePath()))
	// set a custom cluster name to verify that user config works correctly
	.clusterName("my-transport-client-cluster")
	.node();

final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

DataStreamSource<Tuple2<Integer, String>> source = env.addSource(new TestSourceFunction());

Map<String, String> config = new HashMap<>();
// This instructs the sink to emit after every element, otherwise they would be buffered
config.put(ElasticsearchSink.CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS, "1");
config.put("cluster.name", "my-transport-client-cluster");

source.addSink(new ElasticsearchSink<>(config, new ArrayList<InetSocketAddress>(), new TestElasticsearchSinkFunction()));

env.execute("Elasticsearch TransportClient Test");

// verify the results
Client client = node.client();
for (int i = 0; i < NUM_ELEMENTS; i++) {
 GetResponse response = client.get(new GetRequest("my-index",
	 "my-type", Integer.toString(i))).actionGet();
 Assert.assertEquals("message #" + i, response.getSource().get("data"));
}

node.close();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:38,代碼來源:ElasticsearchSinkITCase.java

示例12: openLocalDiscoveryClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
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();
}
 
開發者ID:cerndb,項目名稱:flume-ng-audit-db,代碼行數:9,代碼來源:ElasticSearchTransportClient.java

示例13: activateElasticSearch

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
@Override
protected void activateElasticSearch()
    throws Exception
{
    configuration.refresh();
    ElasticSearchIndexingConfiguration config = configuration.get();

    String clusterName = config.clusterName().get() == null ? DEFAULT_CLUSTER_NAME : config.clusterName().get();
    index = config.index().get() == null ? DEFAULT_INDEX_NAME : config.index().get();
    indexNonAggregatedAssociations = config.indexNonAggregatedAssociations().get();

    Identity identity = hasIdentity.identity().get();
    File homeDir = new File( new File( fileConfig.temporaryDirectory(), identity.toString() ), "home" );
    File logsDir = new File( fileConfig.logDirectory(), identity.toString() );
    File dataDir = new File( fileConfig.dataDirectory(), identity.toString() );
    File confDir = new File( fileConfig.configurationDirectory(), identity.toString() );
    Stream.of( homeDir, logsDir, dataDir, confDir ).forEach( File::mkdirs );
    Settings settings = Settings.builder()
                                .put( "cluster.name", clusterName )
                                .put( "path.home", homeDir.getAbsolutePath() )
                                .put( "path.logs", logsDir.getAbsolutePath() )
                                .put( "path.data", dataDir.getAbsolutePath() )
                                .put( "path.conf", confDir.getAbsolutePath() )
                                .put( "transport.type", "local" )
                                .put( "http.enabled", false )
                                .build();
    node = new Node( settings );
    node.start();
    client = node.client();
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:31,代碼來源:ESFilesystemSupport.java

示例14: ElasticsearchRemoteHttpSink

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
public ElasticsearchRemoteHttpSink(String host, int port, String cluster, String index, String type,
        Mode mode) {
    super(cluster, index, type);
    this.host = host;
    this.port = port;

    Settings.Builder settings = Settings.settingsBuilder()
            .put("cluster.name", getCluster());

    try {
        switch (mode) {
            case TRANSPORT:
                TransportClient tClient = TransportClient.builder().settings(settings).build();
                tClient.addTransportAddress(
                        new InetSocketTransportAddress(InetAddress.getByName(this.host), this.port));
                this.client = tClient;
                break;
            case NODE:
                settings.put("http.enabled", false);
                settings.put("path.home", Files.createTempDir());
                Node node = NodeBuilder.nodeBuilder()
                        .settings(settings)
                        .data(false)
                        .client(true)
                        .node();
                this.client = node.client();
                break;
            default:
                throw new SinkError("Unsupported mode %s", mode);
        }
    } catch (UnknownHostException ex) {
        throw new RuntimeException(ex);
    }
    log.info("Created new client with settings {}:\n{}", settings, client);
}
 
開發者ID:52North,項目名稱:youngs,代碼行數:36,代碼來源:ElasticsearchRemoteHttpSink.java

示例15: createNodeClient

import org.elasticsearch.node.Node; //導入方法依賴的package包/類
private Client createNodeClient() throws Exception {
	ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
	for (Map.Entry<String, String> entry : DEFAULTS.entrySet()) {
		if (!this.properties.getProperties().containsKey(entry.getKey())) {
			settings.put(entry.getKey(), entry.getValue());
		}
	}
	settings.put(this.properties.getProperties());
	Node node = new NodeBuilder().settings(settings)
			.clusterName(this.properties.getClusterName()).node();
	this.releasable = node;
	return node.client();
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:14,代碼來源:ElasticsearchAutoConfiguration.java


注:本文中的org.elasticsearch.node.Node.client方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。