Package org.elasticsearch.node

Examples of org.elasticsearch.node.NodeBuilder


    }
   
  // 1. Link to client (or cluster)
     
    if (_bLocalMode) {
      NodeBuilder nBuilder = NodeBuilder.nodeBuilder().local(true);
      if (null == _elasticClient) {
        _elasticClient = new CrossVersionClient(nBuilder.node().client());
      }
    }
    else if (bRemote) {
     
      if (null == _elasticClient) {
        String sHostname = null;
        String sPort = null;
       
        if (null == hostAndPort) {
          hostAndPort = new PropertiesManager().getElasticUrl();
        }   
        String[] hostPort = hostAndPort.split("[:/]");
        sHostname = hostPort[0];
        sPort = hostPort[1];

        Builder globalSettings = ImmutableSettings.settingsBuilder();
        Settings snode = globalSettings.put("cluster.name", _clusterName).build();
        TransportClient tmp = new TransportClient(snode);
        _elasticClient = new CrossVersionClient(tmp.addTransportAddress(new InetSocketTransportAddress(sHostname, Integer.parseInt(sPort))));
      }
     
    } //TESTED
    else { // Create a "no data" cluster
     
      if (null == _elasticClient) {
        Builder globalSettings = ImmutableSettings.settingsBuilder();
        Settings snode = globalSettings.put("cluster.name", _clusterName).build();
 
        NodeBuilder nBuilder = NodeBuilder.nodeBuilder().settings(snode);
        nBuilder.data(false); // Don't store your own data
        _elasticClient = new CrossVersionClient(nBuilder.build().start().client());
      }
    }//TOTEST
   
    _sIndexName = sIndexName; 
    _sIndexType = sIndexType; 


    }
   
  // 1. Link to client (or cluster)
     
    if (_bLocalMode) {
      NodeBuilder nBuilder = NodeBuilder.nodeBuilder().local(true);
      if (null == _elasticClient) {
        _elasticClient = new CrossVersionClient(nBuilder.node().client());
      }
    }
    else if (bRemote) {
     
      if (null == _elasticClient) {
        String sHostname = null;
        String sPort = null;
       
        if (null == hostAndPort) {
          hostAndPort = new PropertiesManager().getElasticUrl();
        }   
        String[] hostPort = hostAndPort.split("[:/]");
        sHostname = hostPort[0];
        sPort = hostPort[1];
 
        Builder globalSettings = ImmutableSettings.settingsBuilder();
        Settings snode = globalSettings.put("cluster.name", _clusterName).build();
        TransportClient tmp = new TransportClient(snode);
        _elasticClient = new CrossVersionClient(tmp.addTransportAddress(new InetSocketTransportAddress(sHostname, Integer.parseInt(sPort))));
      }
     
    } //TESTED
    else { // Create a "no data" cluster
     
      if (null == _elasticClient) {
        Builder globalSettings = ImmutableSettings.settingsBuilder();
        Settings snode = globalSettings.put("cluster.name", _clusterName).build();
 
        NodeBuilder nBuilder = NodeBuilder.nodeBuilder().settings(snode);
        nBuilder.data(false); // Don't store your own data
        _elasticClient = new CrossVersionClient(nBuilder.build().start().client());
      }
    }//TOTEST
   
  // 2. Just store the index information  
   

//                put("gateway.type", "fs").
//                put("gateway.fs.location", homeDir.getAbsolutePath()).
        }

        settings.build();
        NodeBuilder nBuilder = nodeBuilder().settings(settings);
        if (!testing) {
            nBuilder.clusterName(CLUSTER);
        } else {
            nBuilder.local(true);
        }

        node = nBuilder.build().start();
        started = true;
        logger.info("Started Node in cluster " + CLUSTER + ". Home folder: " + homeDir.getAbsolutePath());
        return this;
    }

//                put("gateway.type", "fs").
//                put("gateway.fs.location", homeDir.getAbsolutePath()).
        }

        settings.build();
        NodeBuilder nBuilder = nodeBuilder().settings(settings);
        if (!testing) {
            nBuilder.clusterName(CLUSTER);
        } else {
            nBuilder.local(true);
        }

        node = nBuilder.build().start();
        started = true;
        logger.info("Started Node in cluster " + CLUSTER + ". Home folder: " + homeDir.getAbsolutePath());
        return this;
    }

    private Node node;

    @Bean
    public Client elasticSearchClient() throws Exception {
        NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().local(true);
        nodeBuilder.getSettings().put("network.host", "127.0.0.1");
        node = nodeBuilder.node();
        Client client = node.client();
        return client;
    }

            return null;
        }
    }

    public Node buildNode() {
        NodeBuilder builder = nodeBuilder().local(isLocal()).data(isData());
        if (!isLocal() && getClusterName() != null) {
            builder.clusterName(getClusterName());
        }
        return builder.node();
    }

    settings.build();

    // Check Model
    if (this.isLocalMode()) {
      Logger.info("Starting Elastic Search for Play! in Local Mode");
      final NodeBuilder nb = nodeBuilder().settings(settings).local(true).client(false).data(true);
      final Node node = nb.node();
      client = node.client();

    } else {
      Logger.info("Connecting Play! to Elastic Search in Client Mode");
      final TransportClient c = new TransportClient(settings);

  public static boolean createIndex(String appid) {
    if (StringUtils.isBlank(appid) || StringUtils.containsWhitespace(appid) || existsIndex(appid)) {
      return false;
    }
    try {
      NodeBuilder nb = NodeBuilder.nodeBuilder();
      nb.settings().put("number_of_shards", Config.getConfigParam("para.es.shards", "5"));
      nb.settings().put("number_of_replicas", Config.getConfigParam("para.es.replicas", "0"));
      nb.settings().put("auto_expand_replicas", "0-all");
      nb.settings().put("analysis.analyzer.default.type", "standard");
      nb.settings().putArray("analysis.analyzer.default.stopwords",
          "arabic", "armenian", "basque", "brazilian", "bulgarian", "catalan",
          "czech", "danish", "dutch", "english", "finnish", "french", "galician",
          "german", "greek", "hindi", "hungarian", "indonesian", "italian",
          "norwegian", "persian", "portuguese", "romanian", "russian", "spanish",
          "swedish", "turkish");

      String name = appid + "1";
      CreateIndexRequestBuilder create = getClient().admin().indices().prepareCreate(name).
          setSettings(nb.settings().build());

      // default system mapping (all the rest are dynamic)
      create.addMapping("_default_", getDefaultMapping());
      create.execute().actionGet();

        } catch(IOException e) {
        }
      }
    }

    NodeBuilder nBuilder = nodeBuilder().clusterName(clusterName).loadConfigSettings(true).
        settings(settings);

    esNode = nBuilder.node();
    log.info("started elastic search node");
    return this;
  }

    // Node Client will discover other ES nodes running in local JVM
    public Client createNodeClient(ClientType clientType) {
        String dspaceDir = ConfigurationManager.getProperty("dspace.dir");
        Settings settings = ImmutableSettings.settingsBuilder().put("path.data", dspaceDir + "/elasticsearch/").build();

        NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().clusterName(clusterName).data(true).settings(settings);

        if(clientType == ClientType.LOCAL) {
            log.info("Create a Local Node.");
            nodeBuilder = nodeBuilder.local(true);
        } else if(clientType == ClientType.NODE) {
            log.info("Create a nodeClient, allows transport clients to connect");
            nodeBuilder = nodeBuilder.local(false);
        }

        Node node = nodeBuilder.node();
        log.info("Got node");
        client = node.client();
        log.info("Created new node client");
        return client;
    }

TOP

Related Classes of org.elasticsearch.node.NodeBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.