本文整理汇总了Java中org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableSettings.settingsBuilder方法的具体用法?Java ImmutableSettings.settingsBuilder怎么用?Java ImmutableSettings.settingsBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.settings.ImmutableSettings
的用法示例。
在下文中一共展示了ImmutableSettings.settingsBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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);
}
}
示例3: 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();
}
示例4: 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;
}
示例5: 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();
}
示例6: setting
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
public ConfigHelper setting(InputStream in) throws IOException {
if (settingsBuilder == null) {
settingsBuilder = ImmutableSettings.settingsBuilder();
}
settingsBuilder = ImmutableSettings.settingsBuilder().loadFromStream(".json", in);
return this;
}
示例7: initClient
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
private void initClient() {
ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
settingsBuilder.put(ImmutableSettings.Builder.EMPTY_SETTINGS);//keep default classloader
settingsBuilder.put(meta.getSettings());
Settings settings = settingsBuilder.build();
if(meta.getServers().length > 0){
node = null;
TransportClient tClient = new TransportClient(settings);
for(InetSocketTransportAddress address : meta.getServers()){
tClient.addTransportAddress(address);
}
client = tClient;
}
else {
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();
nodeBuilder.settings(settings);
node = nodeBuilder.client(true).node();// this node will not hold data
client = node.client();
node.start();
}
}
示例8: 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();
}
示例9: createNodeClient
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
private Client createNodeClient() throws Exception {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
for (Map.Entry<String, String> entry : DEFAULTS.entrySet()) {
if (!this.properties.getProperties().containsKey(entry.getKey())) {
settings.put(entry.getKey(), entry.getValue());
}
}
settings.put(this.properties.getProperties());
Node node = new NodeBuilder().settings(settings)
.clusterName(this.properties.getClusterName()).node();
this.releasable = node;
return node.client();
}
示例10: createTransportClient
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
private Client createTransportClient(MetricsPluginExtension extension) {
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
builder.classLoader(Settings.class.getClassLoader());
builder.put("cluster.name", extension.getClusterName());
InetSocketTransportAddress address = new InetSocketTransportAddress(extension.getHostname(), extension.getTransportPort());
return new TransportClient(builder.build()).addTransportAddress(address);
}
示例11: testIndexCreationOptions
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
final int shards = 77;
ElasticsearchRunner esr = new ElasticsearchRunner();
esr.start();
CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
ModifiableConfiguration config =
new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE, INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
idx.close();
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");
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
nodeBuilder.client(true).data(false).local(false);
Node n = nodeBuilder.build().start();
GetSettingsRequest request = new GetSettingsRequestBuilder((NodeClient)n.client(), "titan").request();
GetSettingsResponse response = n.client().admin().indices().getSettings(request).actionGet();
assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));
n.stop();
esr.stop();
}
示例12: createClient
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
@SuppressWarnings("resource")
public static Client createClient(ElasticSearchConfig config) {
if (client != null) {
return client;
}
String elasticSearchHost = config.getHost();
int elasticSearchPort = config.getPort();
String clusterName = config.getClusterName();
Builder settingsBuilder = ImmutableSettings.settingsBuilder();
if (clusterName != null) {
settingsBuilder.put("cluster.name", clusterName);
}
Settings settings = settingsBuilder.build();
if (elasticSearchHost != null) {
logger.info("Creating a ElasticSearch TransportClient for address: {}:{}",
elasticSearchHost, elasticSearchPort);
int port = elasticSearchPort != 0 ? elasticSearchPort : 9300;
InetSocketTransportAddress socketAddress = new InetSocketTransportAddress(
elasticSearchHost, port);
client = new TransportClient(settings).addTransportAddress(socketAddress);
return client;
} else {
logger.info("Creating a ElasticSearch Node Client for address: %s:%s",
elasticSearchHost, elasticSearchPort);
clientNode = NodeBuilder.nodeBuilder().client(true).settings(settings).node();
client = clientNode.client();
return client;
}
}
示例13: 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;
}
示例14: buildSettings
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
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();
}
示例15: preStart
import org.elasticsearch.common.settings.ImmutableSettings; //导入方法依赖的package包/类
/**
* @see akka.actor.UntypedActor#preStart()
*/
public void preStart() throws Exception {
// initialize elasticsearch client
ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
settingsBuilder.put("cluster.name", cluster);
Settings settings = settingsBuilder.build();
this.elasticSearchTransportClient = new TransportClient(settings);
this.elasticSearchTransportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
}