Package org.elasticsearch.common.settings.ImmutableSettings

Examples of org.elasticsearch.common.settings.ImmutableSettings.Builder


        }   
        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; 
   
  // 2. Create the index if necessary 
   
    if (null != settings) { // Need to create the index
     
      for (int i = 0; i < 10; i++) { // retry up to 10 times if NoNodeAvailableException found
        try {
          CreateIndexRequest cir = new CreateIndexRequest(_sIndexName);
          String sCachePolicy = properties.getElasticCachePolicy();
          if (null != sCachePolicy) {
            settings.put("index.cache.field.type", sCachePolicy);
          }
          if (null != sMapping) {
            cir.mapping(_sIndexType, sMapping);
          }
          cir.settings(settings.build());
          _elasticClient.admin().indices().create(cir).actionGet();
         
          //(Wait for above operation to be completed)
          _elasticClient.admin().cluster().health(new ClusterHealthRequest(_sIndexName).waitForYellowStatus()).actionGet();
          break;
        }
        catch (NoNodeAvailableException e) {
          // Strange NoNodeAvailableException error I see intermittently on t1.micro
          // Sleep and try again I guess?
          if (9 == i) {
            throw new RuntimeException("elasticsearch.NoNodeAvailableException1: " + _sIndexName + "/" + _clusterName + "/" + hostAndPort);
          }
          try {
            Thread.sleep(1500);
          }
          catch (Exception e2) {} // (ignore)         
        }
        catch (IndexCreationException e) {
          if (e.getRootCause() instanceof IllegalArgumentException) {
            // (probably the mapping is invalid)
            throw new RuntimeException(e.getMessage());
          }
          // (probably just exists)
          break;
        }
        catch (Exception e) {
          // Fine, index probably just exists
          break;
        }
      } // (end retry loop)
     
    } //TESTED - normal NOT clustered
   
    // Either check index exists or wait for above operation to be completed
   
    for (int i = 0; i < 10; i++) { // retry up to 10 times if NoNodeAvailableException found
      try {
        _elasticClient.admin().cluster().health(new ClusterHealthRequest(_sIndexName).waitForYellowStatus()).actionGet();
        break;
      }
      catch (NoNodeAvailableException e) {
        // Strange NoNodeAvailableException error I see intermittently on t1.micro
        // Sleep and try again I guess?
        if (9 == i) {
          throw new RuntimeException("elasticsearch.NoNodeAvailableException2: " + _sIndexName + "/" + _clusterName + "/" + hostAndPort);
        }
        try {
          Thread.sleep(1500);
        }
        catch (Exception e2) {} // (ignore)         
      }
    } // (end retry loop)
     
    //TESTED - throws a horrible slow exception, but does fail
   
  // 3. Sort out replication, if necessary
   
    // First time through, check the replication factor is correct...
    ClusterHealthResponse health =
      _elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName)).actionGet();
   
    ClusterIndexHealth indexStatus = health.getIndices().get(sIndexName);
    if ((null != indexStatus) && (1 == indexStatus.getShards().size())) { // 1 shard => this is a "data local" index
           
      int nNumNodes = health.getNumberOfDataNodes();
      Builder localSettings = ImmutableSettings.settingsBuilder();
      if (nNumNodes > 1) {
        localSettings.put("number_of_replicas", nNumNodes - 1); // (ie shard=1 + replicas==num_nodes)
      }
      else {
        localSettings.put("number_of_replicas", 1); // (System doesn't work very well if has no replicas?)       
      }
      UpdateSettingsUtils.updateSettings(_elasticClient.admin().indices(), sIndexName, localSettings.build());
     
      //(Wait for above operation to be completed)
      _elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName).waitForYellowStatus()).actionGet();
    }
    else if ((null != indexStatus) && (indexStatus.getNumberOfReplicas() > 1)) { // Multi shard index, just need to check there aren't too many replicas for nodes
     
      int nNumNodes = health.getNumberOfDataNodes();
      int nReplicas = indexStatus.getNumberOfReplicas();
      int nNodesPerReplica = properties.getElasticNodesPerReplica();
      if ((nNumNodes > 0) && (nNodesPerReplica > 0)) {
        int nNewReplicas = (nNumNodes + nNodesPerReplica-1)/nNodesPerReplica;
          // (ie round up)
        int nMaxReplicas = properties.getElasticMaxReplicas();
        if (nNewReplicas > nMaxReplicas) {
          nNewReplicas = nMaxReplicas;
        }
       
        if (nNewReplicas != nReplicas) { // Change the number of replicas
          Builder localSettings = ImmutableSettings.settingsBuilder();
          localSettings.put("number_of_replicas", nNewReplicas);
          UpdateSettingsUtils.updateSettings(_elasticClient.admin().indices(), sIndexName, localSettings.build());
         
          //(Wait for above operation to be completed)
          _elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName).waitForYellowStatus()).actionGet();       
        }//TESTED
      }
View Full Code Here


        }   
        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());
      }
View Full Code Here

        // increase maxClauseCount for friend search ... not necessary
        // http://wiki.apache.org/lucene-java/LuceneFAQ#Why_am_I_getting_a_TooManyClauses_exception.3F
//        BooleanQuery.setMaxClauseCount(100000);

        Builder settings = ImmutableSettings.settingsBuilder();
//                put("network.host", "127.0.0.1").
//                //                put("network.bindHost", "127.0.0.0").
//                //                put("network.publishHost", "127.0.0.0").
//                put("index.number_of_shards", 16).
//                put("index.number_of_replicas", 1);

        if (testing) {
            settings.put("gateway.type", "none");
            // default is local
            // none means no data after node restart!
            // does not work when transportclient connects:
//                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);
View Full Code Here

      Logger.debug("Elastic Search Started Already!");
      return;
    }

    // Start Node Builder
    final Builder settings = ImmutableSettings.settingsBuilder();
    // settings.put("client.transport.sniff", true);

    // Import anything from play configuration that starts with elasticsearch.native.
    final Enumeration<Object> keys = Play.configuration.keys();
    while (keys.hasMoreElements()) {
      final String key = (String) keys.nextElement();
      if (key.startsWith("elasticsearch.native.")) {
        final String nativeKey = key.replaceFirst("elasticsearch.native.", "");
        Logger.error("Adding native [" + nativeKey + "," + Play.configuration.getProperty(key) + "]");
        settings.put(nativeKey, Play.configuration.getProperty(key));
      }
    }

    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);
View Full Code Here

        // initialize OrientDB driver
        Properties props = getProperties();
        this.indexKey = props.getProperty("es.index.key", DEFAULT_INDEX_KEY);
        String clusterName = props.getProperty("cluster.name", DEFAULT_CLUSTER_NAME);
        Boolean newdb = Boolean.parseBoolean(props.getProperty("elasticsearch.newdb", "false"));
        Builder settings = settingsBuilder()
                .put("node.local", "true")
                .put("path.data", System.getProperty("java.io.tmpdir") + "/esdata")
                .put("discovery.zen.ping.multicast.enabled", "false")
                .put("index.mapping._id.indexed", "true")
                .put("index.gateway.type", "none")
                .put("gateway.type", "none")
                .put("index.number_of_shards", "1")
                .put("index.number_of_replicas", "0");


        //if properties file contains elasticsearch user defined properties
        //add it to the settings file (will overwrite the defaults).
        settings.put(props);
        System.out.println("ElasticSearch starting node = " + settings.get("cluster.name"));
        System.out.println("ElasticSearch node data path = " + settings.get("path.data"));

        node = nodeBuilder().clusterName(clusterName).settings(settings).node();
        node.start();
        client = node.client();
View Full Code Here

  public Esi4JBean(Settings defaultSettings) {
    _defaultSettings = defaultSettings;
  }

  private DefaultEsi4J createEsi4J() {
    Builder settings = ImmutableSettings.settingsBuilder();
    if (_defaultSettings != null) {
      settings.put(_defaultSettings);
    }
    if (_settings != null) {
      settings.put(_settings);
    }
    if (_properties != null) {
      settings.put(_properties);
    }

    _esi4j = newEsi4J(processSettings(settings).build());

    init(_esi4j);
View Full Code Here

    private final Log log = Log.forClass(this.getClass());
    private Node node;

    public ElasticSearchManager(String datadir) {
        Builder settingsBuilder = ImmutableSettings.settingsBuilder();
        settingsBuilder = settingsBuilder.loadFromClasspath("elasticsearch-local.yml");
        settingsBuilder = settingsBuilder.put("gateway.type", "none");
        settingsBuilder = settingsBuilder.put("cluster.name", "mycluster");
        if (datadir != null) {
            settingsBuilder = settingsBuilder.put("path.data", datadir);
        }


        node = NodeBuilder.nodeBuilder().settings(settingsBuilder).node();
View Full Code Here

  /**
   * @return a new settings object containing all keys starting with oldPrefix
   *         whereas oldPrefix is replaced by newPrefix
   */
  public static Settings getSettings(Settings settings, String oldPrefix, String newPrefix) {
    Builder builder = ImmutableSettings.settingsBuilder();

    for (Entry<String, String> e : settings.getByPrefix(oldPrefix).getAsMap().entrySet()) {
      builder.put(newPrefix + e.getKey(), e.getValue());
    }

    return builder.build();
  }
View Full Code Here

                for (String key : keys) {
                    if (restrictedIndex == null || restrictedIndex.equals(key)) {
                        try {
                            Object indexMap = map.get(key);
                            if (indexMap instanceof Map) {
                                Builder builder = ImmutableSettings.settingsBuilder();
                                Object settingsMap = ((Map<String, Object>) indexMap).get("settings");
                                if (settingsMap != null && settingsMap instanceof Map) {
                                    XContentBuilder settingsBuilder = XContentFactory.contentBuilder(XContentType.JSON);
                                    builder.loadFromSource(settingsBuilder.map((Map<String, Object>) settingsMap).string());
                                }
                                Settings settings = builder.build();
                                CreateIndexRequest cir = new CreateIndexRequest(key, settings);
                                try {
                                    client.admin().indices().create(cir).actionGet();
                                } catch (IndexAlreadyExistsException e1) {
                                    // ignore, maybe a concurrent shard created the index simultaneously
View Full Code Here

        final Index index = new Index("test");
        final String name = "ngr";
        for (int i = 0; i < iters; i++) {
            Version v = randomVersion(random());
            if (v.onOrAfter(Version.V_0_90_2)) {
                Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3).put("token_chars", "letter,digit");
                boolean compatVersion = false;
                if ((compatVersion = random().nextBoolean())) {
                    builder.put("version", "4." + random().nextInt(3));
                    builder.put("side", "back");
                }
                Settings settings = builder.build();
                Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build();
                Tokenizer edgeNGramTokenizer = new EdgeNGramTokenizerFactory(index, indexSettings, name, settings).create();
                edgeNGramTokenizer.setReader(new StringReader("foo bar"));
                if (compatVersion) {
                    assertThat(edgeNGramTokenizer, instanceOf(Lucene43EdgeNGramTokenizer.class));
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.settings.ImmutableSettings.Builder

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.