当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableSettings类代码示例

本文整理汇总了Java中org.elasticsearch.common.settings.ImmutableSettings的典型用法代码示例。如果您正苦于以下问题:Java ImmutableSettings类的具体用法?Java ImmutableSettings怎么用?Java ImmutableSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ImmutableSettings类属于org.elasticsearch.common.settings包,在下文中一共展示了ImmutableSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    Log4jESLoggerFactory.getRootLogger().setLevel("ERROR");
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "ciphergateway").build();
    //Use one and only one Client in your JVM. It's threadsafe.
    Client client = new TransportClient(settings)
        .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

    Long start = System.currentTimeMillis();
//    exportES(client);
//    deleteES(client);
//    importES(client);
//    searchES(client);
    exportAndDeleteES(client);
    client.close();
    Long end = System.currentTimeMillis();
    System.out.println("用时: " + (end - start) + " ms");
  }
 
开发者ID:MoneZhao,项目名称:elasticsearch,代码行数:18,代码来源:App.java

示例2: EsStore

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
public EsStore(String host, int port) {
  String clusterName = Configuration.getProperties().getString("es_cluster_name", "soundwave");
  Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName)
      .put("client.transport.sniff", false).build();
  esClient = new TransportClient(settings)
      .addTransportAddress(
          new InetSocketTransportAddress(host, port));
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:9,代码来源:EsStore.java

示例3: commit

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
@Override
public void commit() {
	if (this.client != null) {
		this.flushIndex(true);
		this.client.admin().indices()
				.refresh(new RefreshRequest(this.indexName)).actionGet();

		// enable index auto refresh
		ImmutableSettings.Builder indexSettings = ImmutableSettings
				.settingsBuilder();
		indexSettings.put("refresh_interval", 1);
		this.client.admin().indices().prepareUpdateSettings(this.indexName)
				.setSettings(indexSettings).execute().actionGet();

		this.client.admin().indices().prepareOptimize(this.indexName)
				.setMaxNumSegments(5).execute().actionGet();
	}
}
 
开发者ID:enricopal,项目名称:STEM,代码行数:19,代码来源:ElasticSearchDatabase.java

示例4: startElasticsearch

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
@BeforeClass
public static void startElasticsearch() throws Exception {
    removeOldDataDir(ES_WORKING_DIR + "/" + clusterName);

    Settings settings = ImmutableSettings.builder()
            .put("path.home", ES_WORKING_DIR)
            .put("path.conf", ES_WORKING_DIR)
            .put("path.data", ES_WORKING_DIR)
            .put("path.work", ES_WORKING_DIR)
            .put("path.logs", ES_WORKING_DIR)
            .put("http.port", HTTP_PORT)
            .put("transport.tcp.port", HTTP_TRANSPORT_PORT)
            .put("index.number_of_shards", "1")
            .put("index.number_of_replicas", "0")
            .put("discovery.zen.ping.multicast.enabled", "false")
            .build();
    node = nodeBuilder().settings(settings).clusterName(clusterName).client(false).node();
    node.start();

}
 
开发者ID:sonyxperiadev,项目名称:lumber-mill,代码行数:21,代码来源:AbstractElasticSearchTest.java

示例5: connect

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
public void connect(String httpAddress, String transportAddress) {
	String cluster_name = getClusterName(httpAddress.split(","));
	
	Settings settings = ImmutableSettings.settingsBuilder()
			.put("client.transport.sniff", true)
			.put("cluster.name", cluster_name).build();
	
	TransportClient client = new TransportClient(settings);
	for (String host : transportAddress.split(",")) {
		if (StringUtils.isBlank(host)) {
			continue;
		}
		
		String ip = StringUtils.substringBefore(host, ":");
		String port = StringUtils.substringAfter(host, ":");
		client.addTransportAddress(new InetSocketTransportAddress(ip, Integer.valueOf(port)));
	}
	
	searchDao = new SearchDao(client);
}
 
开发者ID:lane-cn,项目名称:elasticsql,代码行数:21,代码来源:StatementExecutor.java

示例6: initClient

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
/**
 * 
 * @Description 初始化客户端
 * @param clusterNodes 多个集群节点用逗号分隔:"ip:9300,ip:9300"
 * @param clusterName 如:elasticsearch
 */
public static void initClient(String clusterNodes, String clusterName) {
	if (client == null) {
		lock.lock();
		try {
			if (client == null) {
				Settings settings = ImmutableSettings.settingsBuilder()
						.put("client.transport.sniff", true)
						.put("client", true).put("data", false)
						.put("clusterName", clusterName).build();

				client = new TransportClient(settings);
				for (String clusterNode : clusterNodes.split(",")) {
					String ip = clusterNode.split(":")[0];
					String port = clusterNode.split(":")[1];
					client.addTransportAddress(new InetSocketTransportAddress(
							ip, Integer.parseInt(port)));
				}
			}
		} finally {
			lock.unlock();
		}
	}
}
 
开发者ID:runfriends,项目名称:PurchaseNear,代码行数:30,代码来源:ElasticSearchClient.java

示例7: checkForOrCreateIndex

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:35,代码来源:ElasticSearchIndex.java

示例8: start

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
@Override
public void start() {
    // Start embedded Elasticsearch node
    ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
    settings.put("node.name", "test-node");
    settings.put("path.data", "build/data");

    m_node = NodeBuilder.nodeBuilder()
            .settings(settings)
            .clusterName("test-cluster")
            .data(true)
            .local(true)
            .node();
    m_client = m_node.client();

    // Start polling for index count
    m_timerId = vertx.setPeriodic(1000L, this);
    // Start tests
    super.start();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:21,代码来源:ElasticsearchTest.java

示例9: createAuditIndex

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
private void createAuditIndex() {

        logger.info("will create audit index");

        final Settings auditIndexSettings = ImmutableSettings.builder().put(SETTING_NUMBER_OF_SHARDS, 3).put(SETTING_NUMBER_OF_REPLICAS, 1)
                .build();

        final XContentBuilder auditIndexEventsTypeMapping = Change.getMapping();

        client.admin().indices().prepareCreate(auditIndexName).addMapping(AUDIT_INDEX_INDEXING_TYPE, auditIndexEventsTypeMapping)
        .setSettings(auditIndexSettings).execute(new ActionListener<CreateIndexResponse>() {
            @Override
            public void onResponse(final CreateIndexResponse response) {
                if (!response.isAcknowledged()) {
                    logger.error("Failed to create {}.", auditIndexName);
                    throw new ElasticsearchException("Failed to create index " + auditIndexName);
                }
            }

            @Override
            public void onFailure(final Throwable e) {
                logger.error("Failed to create {}", e, auditIndexName);
            }
        });
    }
 
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:26,代码来源:AuditService.java

示例10: setRandomTranslogSettings

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
private static ImmutableSettings.Builder setRandomTranslogSettings(final Random random, final ImmutableSettings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, RandomInts.randomIntBetween(random, 1, 10000));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(RandomInts.randomIntBetween(random, 1, 300),
                ByteSizeUnit.MB));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD,
                TimeValue.timeValueMinutes(RandomInts.randomIntBetween(random, 1, 60)));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_INTERVAL,
                TimeValue.timeValueMillis(RandomInts.randomIntBetween(random, 1, 10000)));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_DISABLE_FLUSH, random.nextBoolean());
    }
    return builder;
}
 
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:22,代码来源:ElasticsearchIntegrationTest.java

示例11: indexSettings

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
/**
 * Returns a settings object used in {@link #createIndex(String...)} and {@link #prepareCreate(String)} and friends.
 * This method can be overwritten by subclasses to set defaults for the indices that are created by the test.
 * By default it returns a settings object that sets a random number of shards. Number of shards and replicas
 * can be controlled through specific methods.
 */
public Settings indexSettings() {
    final ImmutableSettings.Builder builder = ImmutableSettings.builder();
    if (randomizeNumberOfShardsAndReplicas()) {
        final int numberOfShards = numberOfShards();
        if (numberOfShards > 0) {
            builder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards).build();
        }
        final int numberOfReplicas = numberOfReplicas();
        if (numberOfReplicas >= 0) {
            builder.put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
        }
    }
    // 30% of the time
    if (useCustomDataPath() && (randomInt(9) < 3)) {
        final String dataPath = "data/custom-" + CHILD_JVM_ID + "/" + UUID.randomUUID().toString();
        logger.info("using custom data_path for index: [{}]", dataPath);
        builder.put(IndexMetaData.SETTING_DATA_PATH, dataPath);
    }
    return builder.build();
}
 
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:27,代码来源:ElasticsearchIntegrationTest.java

示例12: prepareBackwardsDataDir

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
/**
 * Return settings that could be used to start a node that has the given zipped home directory.
 */
protected Settings prepareBackwardsDataDir(final File backwardsIndex, final Object... settings) throws IOException {
    final File indexDir = newTempDir();
    final File dataDir = new File(indexDir, "data");
    TestUtil.unzip(backwardsIndex, indexDir);
    assertTrue(dataDir.exists());
    final String[] list = dataDir.list();
    if (list == null || list.length > 1) {
        throw new IllegalStateException("Backwards index must contain exactly one cluster");
    }
    final File src = new File(dataDir, list[0]);
    final File dest = new File(dataDir, internalCluster().getClusterName());
    assertTrue(src.exists());
    src.renameTo(dest);
    assertFalse(src.exists());
    assertTrue(dest.exists());
    final ImmutableSettings.Builder builder = ImmutableSettings.builder().put(settings).put("gateway.type", "local") // this is important we need to recover from gateway
            .put("path.data", dataDir.getPath());

    final File configDir = new File(indexDir, "config");
    if (configDir.exists()) {
        builder.put("path.conf", configDir.getPath());
    }
    return builder.build();
}
 
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:28,代码来源:ElasticsearchIntegrationTest.java

示例13: init

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
@Override
public void init(Map<String, String> props) {
    String host = props.get(PropConst.HOST);
    if (host == null) {
        throw new IllegalArgumentException("Host does not specified");
    }
    String port = props.get(PropConst.PORT);
    if (port == null) {
        throw new IllegalArgumentException("Port does not specified");
    }
    String clusterName = props.get(PropConst.CLUSTER_NAME);
    if (clusterName == null) {
        throw new IllegalArgumentException("Cluster name does not specified");
    }
    client = (new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build()))
            .addTransportAddress(new InetSocketTransportAddress(host, Integer.valueOf(port)));
}
 
开发者ID:presidentio,项目名称:test-data-generator,代码行数:18,代码来源:AbstractEsSink.java

示例14: getClient

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的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

示例15: getJavaClient

import org.elasticsearch.common.settings.ImmutableSettings; //导入依赖的package包/类
public static Client getJavaClient() {
	if (javaClient == null) {
		try {
			
			String es_cluster_name=AnalyseLogTaskLauncher.taskConfig.getEs_cluster_name();

			ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder().put("cluster.name", es_cluster_name);
			Settings settings = builder.build();

			List<String> cluster_ips = AnalyseLogTaskLauncher.taskConfig.getEs_ips();
			TransportClient transportClient = new TransportClient(settings);
			for (String string : cluster_ips) {
				String[] strs=string.split(":");
				transportClient.addTransportAddress(new InetSocketTransportAddress(strs[0], Integer.parseInt(strs[1])));
			}
			javaClient = transportClient;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	return javaClient;
}
 
开发者ID:yunshouhu,项目名称:LogAnalyzer,代码行数:25,代码来源:Tool.java


注:本文中的org.elasticsearch.common.settings.ImmutableSettings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。