本文整理匯總了Java中org.elasticsearch.common.settings.ImmutableSettings.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java ImmutableSettings.Builder方法的具體用法?Java ImmutableSettings.Builder怎麽用?Java ImmutableSettings.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.common.settings.ImmutableSettings
的用法示例。
在下文中一共展示了ImmutableSettings.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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();
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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();
}
示例6: 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();
}
示例7: 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;
}
示例8: startLocalNode
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
private ElasticClient startLocalNode(String clusterName, boolean refresh, int version) {
final ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()
.put("node.name", applicationName + "-local-node" + System.currentTimeMillis()).put("node.data", true)
.put("cluster.name", clusterName).put("index.store.type", "memory")
.put("index.store.fs.memory.enabled", "true").put("gateway.type", "none")
.put("path.data", "./local-cluster/" + clusterName + "/data")
.put("path.work", "./local-cluster/" + clusterName + "/work")
.put("path.logs", "./local-cluster/" + clusterName + "/logs").put("index.number_of_shards", "1")
.put("index.number_of_replicas", "0").put("cluster.routing.schedule", "50ms");
final Node localNode = NodeBuilder.nodeBuilder().settings(builder).node();
final Client client = localNode.client();
client.admin().cluster().prepareHealth().setWaitForYellowStatus().setTimeout(TimeValue.timeValueMinutes(1))
.execute().actionGet();
return new ElasticClient(client, applicationName, refresh, version);
}
示例9: updateIndexSetting
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
public static void updateIndexSetting(Client client, String index, String key, Object value) throws IOException {
if (client == null) {
throw new IOException("no client");
}
if (index == null) {
throw new IOException("no index name given");
}
if (key == null) {
throw new IOException("no key given");
}
if (value == null) {
throw new IOException("no value given");
}
ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
settingsBuilder.put(key, value.toString());
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(index)
.settings(settingsBuilder);
client.admin().indices().updateSettings(updateSettingsRequest).actionGet();
}
示例10: loadSettings
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
/**
* Load settings from resource file
*
* @return
* @throws Exception
*/
ImmutableSettings.Builder loadSettings() throws Exception {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
// set default settings
settings.put("client.transport.sniff", sniffing);
if (clusterName != null) {
settings.put("cluster.name", clusterName);
}
// load settings
if (localConfig != null) {
Logger.debug("Elasticsearch : Load settings from " + localConfig);
try {
settings.loadFromClasspath(localConfig);
} catch (SettingsException settingsException) {
Logger.error("Elasticsearch : Error when loading settings from " + localConfig);
throw new Exception(settingsException);
}
}
settings.build();
Logger.info("Elasticsearch : Settings " + settings.internalMap().toString());
return settings;
}
示例11: start
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
public static void start() throws Exception {
ImmutableSettings.Builder settings = config.loadSettings();
if (config.isLocalMode()) {
Logger.info("ElasticSearch : Starting in Local Mode");
NodeBuilder nb = nodeBuilder().settings(settings).local(true).client(false).data(true);
node = nb.node();
Logger.info("ElasticSearch : Started in Local Mode");
}
client = JestClientWrapper.jestClient(config);
// Check Client
if (client == null) {
throw new Exception("ElasticSearch Client cannot be null - please check the configuration provided and the health of your ElasticSearch instances.");
}
}
示例12: testIndexCreationOptions
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
@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();
}
示例13: indexSettings
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
@Override
public Settings indexSettings() {
final ImmutableSettings.Builder builder = ImmutableSettings.builder();
builder.put(SETTING_NUMBER_OF_SHARDS, 3);
builder.put(SETTING_NUMBER_OF_REPLICAS, 1);
return builder.build();
}
示例14: createTransportClient
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
/**
* Create transport client
* @param port
* @return TransportClient
*/
@SuppressWarnings("resource")
private TransportClient createTransportClient(int port){
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
TransportClient client = new TransportClient(settings);
try{
client = client.addTransportAddress(new InetSocketTransportAddress("localhost", port));
} catch(Exception e) {
LOGGER.error("Couldn't create transport client on Port: " + port + ". ", e);
}
return client;
}
示例15: setRandomMerge
import org.elasticsearch.common.settings.ImmutableSettings; //導入方法依賴的package包/類
private static ImmutableSettings.Builder setRandomMerge(final Random random, final ImmutableSettings.Builder builder) {
if (random.nextBoolean()) {
builder.put(AbstractMergePolicyProvider.INDEX_COMPOUND_FORMAT,
random.nextBoolean() ? random.nextDouble() : random.nextBoolean());
}
Class<? extends MergePolicyProvider<?>> mergePolicy = TieredMergePolicyProvider.class;
switch (random.nextInt(5)) {
case 4:
mergePolicy = LogByteSizeMergePolicyProvider.class;
break;
case 3:
mergePolicy = LogDocMergePolicyProvider.class;
break;
case 0:
mergePolicy = null;
}
if (mergePolicy != null) {
builder.put(MergePolicyModule.MERGE_POLICY_TYPE_KEY, mergePolicy.getName());
}
if (random.nextBoolean()) {
builder.put(MergeSchedulerProvider.FORCE_ASYNC_MERGE, random.nextBoolean());
}
switch (random.nextInt(5)) {
case 4:
builder.put(MergeSchedulerModule.MERGE_SCHEDULER_TYPE_KEY, SerialMergeSchedulerProvider.class.getName());
break;
case 3:
builder.put(MergeSchedulerModule.MERGE_SCHEDULER_TYPE_KEY, ConcurrentMergeSchedulerProvider.class);
final int maxThreadCount = RandomInts.randomIntBetween(random, 1, 4);
final int maxMergeCount = RandomInts.randomIntBetween(random, maxThreadCount, maxThreadCount + 4);
builder.put(ConcurrentMergeSchedulerProvider.MAX_MERGE_COUNT, maxMergeCount);
builder.put(ConcurrentMergeSchedulerProvider.MAX_THREAD_COUNT, maxThreadCount);
break;
}
return builder;
}