org.elasticsearch.node.Node.client()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中org.elasticsearch.node.Node.client()方法的一些代码示例,展示了Node.client()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.client()方法的具体详情如下:
包路径:org.elasticsearch.node.Node
类名称:Node
方法名:client

Node.client介绍

[英]A client that can be used to execute actions (operations) against the cluster.
[中]可用于对集群执行操作(操作)的客户端。

代码示例

代码示例来源:origin: stackoverflow.com

  1. Node node = nodeBuilder().clusterName("yourcluster").client(true).node();
  2. Client client = node.client();

代码示例来源:origin: SonarSource/sonarqube

  1. public EsClient client() {
  2. return new EsClient(SHARED_NODE.client());
  3. }

代码示例来源:origin: apache/flume

  1. private void openLocalDiscoveryClient() {
  2. logger.info("Using ElasticSearch AutoDiscovery mode");
  3. Node node = NodeBuilder.nodeBuilder().client(true).local(true).node();
  4. if (client != null) {
  5. client.close();
  6. }
  7. client = node.client();
  8. }

代码示例来源:origin: SonarSource/sonarqube

  1. private static void deleteIndexIfExists(String name) {
  2. try {
  3. DeleteIndexResponse response = SHARED_NODE.client().admin().indices().prepareDelete(name).get();
  4. checkState(response.isAcknowledged(), "Fail to drop the index " + name);
  5. } catch (IndexNotFoundException e) {
  6. // ignore
  7. }
  8. }

代码示例来源:origin: stagemonitor/stagemonitor

  1. protected static void refresh() {
  2. node.client().admin().indices().prepareRefresh().get();
  3. }
  4. }

代码示例来源:origin: loklak/loklak_server

  1. /**
  2. * create a elasticsearch node client (embedded elasticsearch)
  3. * @param settings
  4. */
  5. public ElasticsearchClient(final Settings.Builder settings) {
  6. // create a node
  7. this.elasticsearchNode = NodeBuilder.nodeBuilder().local(false).settings(settings).node();
  8. // create a client
  9. this.elasticsearchClient = elasticsearchNode.client();
  10. }

代码示例来源:origin: stagemonitor/stagemonitor

  1. protected void deleteAll() {
  2. node.client().admin().indices().prepareDelete("_all").get();
  3. }

代码示例来源:origin: SonarSource/sonarqube

  1. private void setIndexSettings(String index, Map<String, Object> settings) {
  2. UpdateSettingsResponse response = SHARED_NODE.client().admin().indices()
  3. .prepareUpdateSettings(index)
  4. .setSettings(settings)
  5. .get();
  6. checkState(response.isAcknowledged());
  7. }

代码示例来源:origin: SonarSource/sonarqube

  1. @Override
  2. protected void after() {
  3. if (isCustom) {
  4. // delete non-core indices
  5. String[] existingIndices = SHARED_NODE.client().admin().indices().prepareGetIndex().get().getIndices();
  6. Stream.of(existingIndices)
  7. .filter(i -> !CORE_INDICES_NAMES.contains(i))
  8. .forEach(EsTester::deleteIndexIfExists);
  9. }
  10. BulkIndexer.delete(client(), new IndexType("_all", ""), client().prepareSearch("_all").setQuery(matchAllQuery()));
  11. }

代码示例来源:origin: stagemonitor/stagemonitor

  1. private static void startElasticsearch() throws Exception {
  2. try {
  3. FileUtils.deleteDirectory(new File("build/elasticsearch"));
  4. } catch (IOException e) {
  5. // ignore
  6. }
  7. final Settings settings = Settings.builder()
  8. .put("path.home", "build/elasticsearch")
  9. .put("node.name", "junit-es-node")
  10. .put("path.logs", "build/elasticsearch/logs")
  11. .put("path.data", "build/elasticsearch/data")
  12. .put("transport.type", "local")
  13. .put("http.type", "netty4")
  14. .build();
  15. node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class));
  16. node.start();
  17. node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get();
  18. }

代码示例来源:origin: apache/flink

  1. .node();
  2. Client client = node.client();

代码示例来源:origin: SonarSource/sonarqube

  1. CreateIndexResponse indexResponse = SHARED_NODE.client().admin().indices()
  2. .prepareCreate(index.getName())
  3. .setSettings(settings)
  4. throw new IllegalStateException("Failed to create index " + index.getName());
  5. SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get();
  6. PutMappingResponse mappingResponse = SHARED_NODE.client().admin().indices().preparePutMapping(index.getName())
  7. .setType(entry.getKey())
  8. .setSource(entry.getValue().getAttributes())
  9. SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get();
  10. result.add(index);

代码示例来源:origin: SonarSource/sonarqube

  1. /**
  2. * Get all the indexed documents (no paginated results). Results are not sorted.
  3. */
  4. public List<SearchHit> getDocuments(IndexType indexType) {
  5. SearchRequestBuilder req = SHARED_NODE.client().prepareSearch(indexType.getIndex()).setTypes(indexType.getType()).setQuery(matchAllQuery());
  6. EsUtils.optimizeScrollRequest(req);
  7. req.setScroll(new TimeValue(60000))
  8. .setSize(100);
  9. SearchResponse response = req.get();
  10. List<SearchHit> result = newArrayList();
  11. while (true) {
  12. Iterables.addAll(result, response.getHits());
  13. response = SHARED_NODE.client().prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
  14. // Break condition: No hits are returned
  15. if (response.getHits().getHits().length == 0) {
  16. break;
  17. }
  18. }
  19. return result;
  20. }

代码示例来源:origin: thinkaurelius/titan

  1. @Override
  2. public Connection connect(Configuration config) throws IOException {
  3. log.debug("Configuring Node Client");
  4. ImmutableSettings.Builder settingsBuilder = settingsBuilder(config);
  5. if (config.has(ElasticSearchIndex.TTL_INTERVAL)) {
  6. String k = "indices.ttl.interval";
  7. settingsBuilder.put(k, config.get(ElasticSearchIndex.TTL_INTERVAL));
  8. log.debug("Set {}: {}", k, config.get(ElasticSearchIndex.TTL_INTERVAL));
  9. }
  10. makeLocalDirsIfNecessary(settingsBuilder, config);
  11. NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
  12. // Apply explicit Titan properties file overrides (otherwise conf-file or ES defaults apply)
  13. if (config.has(ElasticSearchIndex.CLIENT_ONLY)) {
  14. boolean clientOnly = config.get(ElasticSearchIndex.CLIENT_ONLY);
  15. nodeBuilder.client(clientOnly).data(!clientOnly);
  16. }
  17. if (config.has(ElasticSearchIndex.LOCAL_MODE))
  18. nodeBuilder.local(config.get(ElasticSearchIndex.LOCAL_MODE));
  19. if (config.has(ElasticSearchIndex.LOAD_DEFAULT_NODE_SETTINGS))
  20. nodeBuilder.loadConfigSettings(config.get(ElasticSearchIndex.LOAD_DEFAULT_NODE_SETTINGS));
  21. Node node = nodeBuilder.node();
  22. Client client = node.client();
  23. return new Connection(node, client);
  24. }
  25. };

代码示例来源:origin: SonarSource/sonarqube

  1. public void putDocuments(IndexType indexType, Map<String, Object>... docs) {
  2. try {
  3. BulkRequestBuilder bulk = SHARED_NODE.client().prepareBulk()
  4. .setRefreshPolicy(REFRESH_IMMEDIATE);
  5. for (Map<String, Object> doc : docs) {
  6. bulk.add(new IndexRequest(indexType.getIndex(), indexType.getType())
  7. .source(doc));
  8. }
  9. BulkResponse bulkResponse = bulk.get();
  10. if (bulkResponse.hasFailures()) {
  11. throw new IllegalStateException(bulkResponse.buildFailureMessage());
  12. }
  13. } catch (Exception e) {
  14. throw Throwables.propagate(e);
  15. }
  16. }

代码示例来源:origin: floragunncom/search-guard

  1. @SuppressWarnings("resource")
  2. @Test
  3. public void testNodeClientDisallowedWithNonServerCertificate2() throws Exception {
  4. setup();
  5. Assert.assertEquals(clusterInfo.numNodes, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes());
  6. Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus());
  7. final Settings tcSettings = Settings.builder()
  8. .put(minimumSearchGuardSettings(Settings.EMPTY).get(0))
  9. .put("cluster.name", clusterInfo.clustername)
  10. .put("node.data", false)
  11. .put("node.master", false)
  12. .put("node.ingest", false)
  13. .put("path.home", ".")
  14. .put("discovery.initial_state_timeout","8s")
  15. .put("searchguard.ssl.transport.keystore_filepath", FileHelper.getAbsoluteFilePathFromClassPath("spock-keystore.jks"))
  16. .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_ALIAS,"spock")
  17. .build();
  18. log.debug("Start node client");
  19. try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) {
  20. Thread.sleep(50);
  21. Assert.assertEquals(1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
  22. }
  23. }

代码示例来源:origin: floragunncom/search-guard

  1. @SuppressWarnings("resource")
  2. @Test
  3. public void testNodeClientDisallowedWithNonServerCertificate() throws Exception {
  4. setup();
  5. Assert.assertEquals(clusterInfo.numNodes, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes());
  6. Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus());
  7. final Settings tcSettings = Settings.builder()
  8. .put(minimumSearchGuardSettings(Settings.EMPTY).get(0))
  9. .put("cluster.name", clusterInfo.clustername)
  10. .put("node.data", false)
  11. .put("node.master", false)
  12. .put("node.ingest", false)
  13. .put("path.home", ".")
  14. .put("discovery.initial_state_timeout","8s")
  15. .put("searchguard.ssl.transport.keystore_filepath", FileHelper.getAbsoluteFilePathFromClassPath("kirk-keystore.jks"))
  16. .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_ALIAS,"kirk")
  17. .build();
  18. log.debug("Start node client");
  19. try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) {
  20. Thread.sleep(50);
  21. Assert.assertEquals(1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
  22. } catch (Exception e) {
  23. Assert.fail(e.toString());
  24. }
  25. }

代码示例来源:origin: floragunncom/search-guard

  1. @SuppressWarnings("resource")
  2. @Test
  3. public void testNodeClientAllowedWithServerCertificate() throws Exception {
  4. setup();
  5. Assert.assertEquals(clusterInfo.numNodes, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes());
  6. Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus());
  7. final Settings tcSettings = Settings.builder()
  8. .put(minimumSearchGuardSettings(Settings.EMPTY).get(0))
  9. .put("cluster.name", clusterInfo.clustername)
  10. .put("node.data", false)
  11. .put("node.master", false)
  12. .put("node.ingest", false)
  13. .put("path.home", ".")
  14. .put("discovery.initial_state_timeout","8s")
  15. .putList("discovery.zen.ping.unicast.hosts", clusterInfo.nodeHost+":"+clusterInfo.nodePort)
  16. .build();
  17. log.debug("Start node client");
  18. try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) {
  19. Thread.sleep(50);
  20. Assert.assertEquals(clusterInfo.numNodes+1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());
  21. }
  22. }

代码示例来源:origin: SonarSource/sonarqube

  1. public void putDocuments(IndexType indexType, BaseDoc... docs) {
  2. try {
  3. BulkRequestBuilder bulk = SHARED_NODE.client().prepareBulk()
  4. .setRefreshPolicy(REFRESH_IMMEDIATE);
  5. for (BaseDoc doc : docs) {
  6. bulk.add(new IndexRequest(indexType.getIndex(), indexType.getType(), doc.getId())
  7. .parent(doc.getParent())
  8. .routing(doc.getRouting())
  9. .source(doc.getFields()));
  10. }
  11. BulkResponse bulkResponse = bulk.get();
  12. if (bulkResponse.hasFailures()) {
  13. throw new IllegalStateException(bulkResponse.buildFailureMessage());
  14. }
  15. } catch (Exception e) {
  16. throw Throwables.propagate(e);
  17. }
  18. }

代码示例来源:origin: thinkaurelius/titan

  1. @Test
  2. public void testIndexCreationOptions() throws InterruptedException, BackendException {
  3. final int shards = 77;
  4. ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
  5. esr.start();
  6. CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
  7. cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
  8. cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
  9. ModifiableConfiguration config =
  10. new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
  11. cc, BasicConfiguration.Restriction.NONE);
  12. config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
  13. Configuration indexConfig = config.restrictTo(INDEX_NAME);
  14. IndexProvider idx = new ElasticSearchIndex(indexConfig);
  15. simpleWriteAndQuery(idx);
  16. ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
  17. settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
  18. settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
  19. settingsBuilder.put("cluster.name", "indexCreationOptions");
  20. NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
  21. nodeBuilder.client(true).data(false).local(false);
  22. Node n = nodeBuilder.build().start();
  23. GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
  24. assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));
  25. idx.close();
  26. n.stop();
  27. esr.stop();
  28. }

相关文章