Java Code Examples for org.elasticsearch.common.settings.ImmutableSettings#Builder

The following examples show how to use org.elasticsearch.common.settings.ImmutableSettings#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreLocalClientProvider.java    From elasticsearch-inout-plugin with Apache License 2.0 6 votes vote down vote up
protected Settings buildNodeSettings() {
    // Build settings
    ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
            .put("node.name", "node-test-" + System.currentTimeMillis())
            .put("node.data", true)
            .put("cluster.name", "cluster-test-" + NetworkUtils.getLocalAddress().getHostName())
            .put("path.data", "./target/elasticsearch-test/data")
            .put("path.work", "./target/elasticsearch-test/work")
            .put("path.logs", "./target/elasticsearch-test/logs")
            .put("index.number_of_shards", "1")
            .put("index.number_of_replicas", "0")
            .put("cluster.routing.schedule", "50ms")
            .put("node.local", true);

    if (settings != null) {
        builder.put(settings);
    }

    return builder.build();
}
 
Example 2
Source File: SrvDiscoveryIntegrationTest.java    From elasticsearch-srv-discovery with MIT License 6 votes vote down vote up
@Test
public void testClusterSrvDiscoveryWith5Nodes() throws Exception {
    ImmutableSettings.Builder b = settingsBuilder()
        .put("node.mode", "network")
        .put("discovery.zen.ping.multicast.enabled", "false")
        .put("discovery.type", "srvtest")
        .put(SrvUnicastHostsProvider.DISCOVERY_SRV_QUERY, Constants.TEST_QUERY);

    assertEquals(cluster().size(), 0);

    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_0_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_1_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_2_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_3_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_4_TRANSPORT_TCP_PORT)).build());

    assertEquals(cluster().size(), 5);
}
 
Example 3
Source File: InternalEsClient.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * インデックスを作成する.
 * @param index インデックス名
 * @param mappings マッピング情報
 * @return 非同期応答
 */
public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) {
    this.fireEvent(Event.creatingIndex, index);
    CreateIndexRequestBuilder cirb =
            new CreateIndexRequestBuilder(esTransportClient.admin().indices()).setIndex(index);

    // cjkアナライザ設定
    ImmutableSettings.Builder indexSettings = ImmutableSettings.settingsBuilder();
    indexSettings.put("analysis.analyzer.default.type", "cjk");
    cirb.setSettings(indexSettings);

    if (mappings != null) {
        for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) {
            cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString());
        }
    }
    return cirb.execute();
}
 
Example 4
Source File: ElasticSearchIndex.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 * If ES already contains this instance's target index, then do nothing.
 * Otherwise, create the index, then wait {@link #CREATE_SLEEP}.
 * <p>
 * The {@code client} field must point to a live, connected client.
 * The {@code indexName} field must be non-null and point to the name
 * of the index to check for existence or create.
 *
 * @param config the config for this ElasticSearchIndex
 * @throws java.lang.IllegalArgumentException if the index could not be created
 */
private void checkForOrCreateIndex(Configuration config) {
    Preconditions.checkState(null != client);

    //Create index if it does not already exist
    IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet();
    if (!response.isExists()) {

        ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();

        ElasticSearchSetup.applySettingsFromTitanConf(settings, config, ES_CREATE_EXTRAS_NS);

        CreateIndexResponse create = client.admin().indices().prepareCreate(indexName)
                .setSettings(settings.build()).execute().actionGet();
        try {
            final long sleep = config.get(CREATE_SLEEP);
            log.debug("Sleeping {} ms after {} index creation returned from actionGet()", sleep, indexName);
            Thread.sleep(sleep);
        } catch (InterruptedException e) {
            throw new TitanException("Interrupted while waiting for index to settle in", e);
        }
        if (!create.isAcknowledged()) throw new IllegalArgumentException("Could not create index: " + indexName);
    }
}
 
Example 5
Source File: ClientFactory.java    From storm-trident-elasticsearch with Apache License 2.0 5 votes vote down vote up
private Settings buildSettings(String clusterName) {
    ImmutableSettings.Builder sb = ImmutableSettings.settingsBuilder().put("node.client", true);

    if( StringUtils.isNotEmpty(clusterName)) sb.put("cluster.name", clusterName);
    if( settings != null) sb.put(settings);

    return sb.build();
}
 
Example 6
Source File: ElasticSearchClient.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void addCustomESProperties(ImmutableSettings.Builder settingsBuilder, HashMap<String, Object> properties) {
  for (Map.Entry<String, Object> property : properties.entrySet()) {
    if (property.getKey().toLowerCase().startsWith("es.")) {
      settingsBuilder.put(property.getKey().substring(3), property.getValue());
    }
  }
}
 
Example 7
Source File: EsProvider.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Create the transport client
 * @return
 */
private Client createTransportClient() {
    final String clusterName = indexFig.getClusterName();
    final int port = indexFig.getPort();

    ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put( "cluster.name", clusterName )
        .put( "client.transport.sniff", true );

    String nodeName = indexFig.getNodeName();

    if ( "default".equals( nodeName ) ) {
        // no nodeName was specified, use hostname
        try {
            nodeName = InetAddress.getLocalHost().getHostName();
        }
        catch ( UnknownHostException ex ) {
            nodeName = "client-" + RandomStringUtils.randomAlphabetic( 8 );
            logger.warn( "Couldn't get hostname to use as ES node name, using {}", nodeName );
        }
    }

    settings.put( "node.name", nodeName );


    TransportClient transportClient = new TransportClient( settings.build() );

    // we will connect to ES on all configured hosts
    for ( String host : indexFig.getHosts().split( "," ) ) {
        transportClient.addTransportAddress( new InetSocketTransportAddress( host, port ) );
    }

    return transportClient;
}
 
Example 8
Source File: NodeTestHelper.java    From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License 5 votes vote down vote up
public static Node createNode(String clusterName, int graphitePort, String refreshInterval, String includeRegex,
                              String excludeRegex, String prefix) throws IOException {
    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();

    settingsBuilder.put("path.conf", NodeTestHelper.class.getResource("/").getFile());

    settingsBuilder.put("gateway.type", "none");
    settingsBuilder.put("cluster.name", clusterName);
    settingsBuilder.put("index.number_of_shards", 1);
    settingsBuilder.put("index.number_of_replicas", 1);

    settingsBuilder.put("metrics.graphite.host", "localhost");
    settingsBuilder.put("metrics.graphite.port", graphitePort);
    settingsBuilder.put("metrics.graphite.every", refreshInterval);
    if (!Strings.isEmpty(prefix)) {
        settingsBuilder.put("metrics.graphite.prefix", prefix);
    }

    if (Strings.hasLength(includeRegex)) {
        settingsBuilder.put("metrics.graphite.include", includeRegex);
    }

    if (Strings.hasLength(excludeRegex)) {
        settingsBuilder.put("metrics.graphite.exclude", excludeRegex);
    }

    LogConfigurator.configure(settingsBuilder.build());

    return NodeBuilder.nodeBuilder().settings(settingsBuilder.build()).node();
}
 
Example 9
Source File: SearchIndexingServiceImpl.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() throws Exception {
    log.info("Instantiating jestSearchIndexingService...");
    log.info(String.format("Checking if %s needs to be created", LOCATION_INDEX_NAME));
    IndicesExists indicesExists = new IndicesExists.Builder(LOCATION_INDEX_NAME).build();
    JestResult r = jestClient.execute(indicesExists);

    if (!r.isSucceeded()) {
        log.info("Index does not exist. Creating index...");
        // create new index (if u have this in elasticsearch.yml and prefer
        // those defaults, then leave this out
        ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
        settings.put("number_of_shards", 1);
        settings.put("number_of_replicas", 0);

        CreateIndex.Builder builder = new CreateIndex.Builder(LOCATION_INDEX_NAME);
        builder.settings(settings.build().getAsMap());
        CreateIndex createIndex = builder.build();

        log.info(createIndex.toString());

        jestClient.execute(createIndex);

        log.info("Index created");
    } else {
        log.info("Index already exist!");
    }
}
 
Example 10
Source File: ElasticSearchService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected Node initializeElasticSearchNode(Map<String, String> properties) {
    ImmutableSettings.Builder settings = settingsBuilder().put(properties);

    return nodeBuilder()
            .client(clientNode)
            .settings(settings)
            .local(localNode).node();
}
 
Example 11
Source File: ClientFactory.java    From storm-trident-elasticsearch with Apache License 2.0 5 votes vote down vote up
private Settings buildSettings( ) {
    ImmutableSettings.Builder sb = ImmutableSettings.settingsBuilder()
            .put("node.name", "elastic-storm-test")
            .put("node.local", true)
            .put("index.store.type", "memory");

    if( settings != null) sb.put(settings);

    return sb.build();
}
 
Example 12
Source File: ClientFactory.java    From storm-trident-elasticsearch with Apache License 2.0 5 votes vote down vote up
private Settings buildSettings(String clusterName) {
    ImmutableSettings.Builder sb = ImmutableSettings.settingsBuilder();
    if( StringUtils.isNotEmpty(clusterName)) sb.put("cluster.name", clusterName);
    if( settings != null) sb.put(settings);

    return sb.build();
}
 
Example 13
Source File: SimpleTests.java    From elasticsearch-topk-plugin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void startNode() {
    ImmutableSettings.Builder finalSettings = settingsBuilder()
            .put("cluster.name", CLUSTER)
            .put("discovery.zen.ping.multicast.enabled", false)
            .put("node.local", true)
            .put("gateway.type", "none")
    		.put("cluster.routing.allocation.disk.threshold_enabled", false);
    node = nodeBuilder().settings(finalSettings.put("node.name", "node1").build()).build().start();
    node2 = nodeBuilder().settings(finalSettings.put("node.name", "node2").build()).build().start();

    client = node.client();
}
 
Example 14
Source File: ElasticSearchService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected Node initializeElasticSearchNode(Map<String, String> properties) {
    ImmutableSettings.Builder settings = settingsBuilder().put(properties);

    return nodeBuilder()
            .client(clientNode)
            .settings(settings)
            .local(localNode).node();
}
 
Example 15
Source File: SrvDiscoveryIntegrationTest.java    From elasticsearch-srv-discovery with MIT License 5 votes vote down vote up
@Test
public void testClusterSrvDiscoveryWith2Nodes() throws Exception {
    ImmutableSettings.Builder b = settingsBuilder()
        .put("node.mode", "network")
        .put("discovery.zen.ping.multicast.enabled", "false")
        .put("discovery.type", "srvtest")
        .put(SrvUnicastHostsProvider.DISCOVERY_SRV_QUERY, Constants.TEST_QUERY);

    assertEquals(cluster().size(), 0);

    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_0_TRANSPORT_TCP_PORT)).build());
    internalCluster().startNode(b.put("transport.tcp.port", String.valueOf(Constants.NODE_1_TRANSPORT_TCP_PORT)).build());

    assertEquals(cluster().size(), 2);
}
 
Example 16
Source File: ElasticSearchConfigTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
    final int shards = 77;

    ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
    esr.start();
    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
    ModifiableConfiguration config =
            new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
                    cc, BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);



    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
    settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
    settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
    settingsBuilder.put("cluster.name", "indexCreationOptions");
    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
    nodeBuilder.client(true).data(false).local(false);
    Node n = nodeBuilder.build().start();

    GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
    assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));

    idx.close();
    n.stop();
    esr.stop();
}
 
Example 17
Source File: ESTimedRotatingAdapter.java    From opensoc-streaming with Apache License 2.0 4 votes vote down vote up
@Override
public boolean initializeConnection(String ip, int port,
		String cluster_name, String index_name, String document_name,
		int bulk_size, String date_format) throws Exception {

	bulk_set = new HashBag();

	_LOG.trace("[OpenSOC] Initializing ESBulkAdapter...");

	try {
		_ip = ip;
		_port = port;
		_cluster_name = cluster_name;
		_index_name = index_name;
		_document_name = document_name;
		_bulk_size = bulk_size;
		

		dateFormat = new SimpleDateFormat(date_format);

		System.out.println("Bulk indexing is set to: " + _bulk_size);

		ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder() ;	
		
		if(tuning_settings != null && tuning_settings.size() > 0)
		{
				builder.put(tuning_settings);
		}
		
		builder.put("cluster.name", _cluster_name);
		builder.put("client.transport.ping_timeout","500s");
		
		
		settings = builder.build();
				
		client = new TransportClient(settings)
				.addTransportAddress(new InetSocketTransportAddress(_ip,
						_port));

		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
Example 18
Source File: ClientFactory.java    From storm-trident-elasticsearch with Apache License 2.0 4 votes vote down vote up
protected Settings buildSettings( ) {
    ImmutableSettings.Builder sb = ImmutableSettings.settingsBuilder().put("node.local", "true");
    if( settings != null) sb.put(settings);

    return sb.build();
}
 
Example 19
Source File: ElasticSearchClient.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
protected Client init() {
    Client client = null;

    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.builder()
        .put("cluster.name", historyPluginConfiguration.getEsClusterName());

    if (historyPluginConfiguration.isTransportClient()) {
      // sniff for rest of cluster settingsBuilder.put("client.transport.sniff", true);
      addCustomESProperties(settingsBuilder, historyPluginConfiguration.getProperties());

      TransportClient transportClient = new TransportClient(settingsBuilder).addTransportAddress(
          new InetSocketTransportAddress(historyPluginConfiguration.getEsHost(), Integer.parseInt(historyPluginConfiguration.getEsPort())));
      LOGGER.info("Successfully connected to " + transportClient.connectedNodes());
      client = transportClient;
    } else {
      if (esNode == null) {
        // initialize default settings
        settingsBuilder
            .put("node.name", "rocking-camunda-bpm-history")
            .put("node.client", true) // make node a client, so it won't become a master
            .put("node.local", false)
            .put("node.data", false)
            .put("node.http.enabled", true);
//            .put("discovery.zen.ping.multicast.enabled", false)
//            .put("discovery.zen.ping.unicast.hosts", "127.0.0.1:9300");

        addCustomESProperties(settingsBuilder, historyPluginConfiguration.getProperties());

        esNode = NodeBuilder.nodeBuilder()
            .loadConfigSettings(true)
            .settings(settingsBuilder)
            .build();

        if (LOGGER.isLoggable(Level.INFO)) {
          LOGGER.info("Initialized node with settings: " + esNode.settings().getAsMap().toString());
        }

        esNode.start();
      }

      client = esNode.client();
    }

    return client;
  }