当前位置: 首页>>代码示例>>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;未经允许,请勿转载。