本文整理汇总了Java中org.elasticsearch.common.settings.Settings.Builder.build方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.build方法的具体用法?Java Builder.build怎么用?Java Builder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.settings.Settings.Builder
的用法示例。
在下文中一共展示了Builder.build方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initESClient
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
@Bean
public TransportClient initESClient() throws NumberFormatException, UnknownHostException{
String ip = env.getProperty("spring.es.ip");
String port = env.getProperty("spring.es.port");
String clusterName = env.getProperty("spring.es.cluster_name");
Builder builder = Settings.builder().put("cluster.name", clusterName).put("client.transport.sniff", true);
Settings esSettings = builder.build();
TransportClient client = new PreBuiltTransportClient(esSettings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), Integer.parseInt(port)));
logger.info("ES Client 初始化成功, ip : {}, port : {}, cluster_name : {}", ip, port, clusterName);
return client;
}
示例2: getSettings
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
private Settings getSettings(int nodeOrdinal, long nodeSeed, Settings others) {
Builder builder = Settings.builder().put(defaultSettings)
.put(getRandomNodeSettings(nodeSeed));
Settings settings = nodeConfigurationSource.nodeSettings(nodeOrdinal);
if (settings != null) {
if (settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) != null) {
throw new IllegalStateException("Tests must not set a '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "' as a node setting set '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "': [" + settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) + "]");
}
builder.put(settings);
}
if (others != null) {
builder.put(others);
}
builder.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName);
return builder.build();
}
示例3: testBackwardsCompatibilityEdgeNgramTokenFilter
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public void testBackwardsCompatibilityEdgeNgramTokenFilter() throws Exception {
int iters = scaledRandomIntBetween(20, 100);
for (int i = 0; i < iters; i++) {
final Index index = new Index("test", "_na_");
final String name = "ngr";
Version v = randomVersion(random());
Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3);
boolean reverse = random().nextBoolean();
if (reverse) {
builder.put("side", "back");
}
Settings settings = builder.build();
Settings indexSettings = newAnalysisSettingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, v.id).build();
Tokenizer tokenizer = new MockTokenizer();
tokenizer.setReader(new StringReader("foo bar"));
TokenStream edgeNGramTokenFilter = new EdgeNGramTokenFilterFactory(IndexSettingsModule.newIndexSettings(index, indexSettings), null, name, settings).create(tokenizer);
if (reverse) {
assertThat(edgeNGramTokenFilter, instanceOf(ReverseStringFilter.class));
} else {
assertThat(edgeNGramTokenFilter, instanceOf(EdgeNGramTokenFilter.class));
}
}
}
示例4: ElasticNamespaceDAO
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public ElasticNamespaceDAO(ElasticDAOConfig config) {
try {
Builder builder = Settings.builder();
// Check for new hosts within the cluster
builder.put(CLIENT_SNIFFING_CONFIG, true);
// specify cluster name
if (config.getClusterName() != null) {
builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
}
Settings settings = builder.build();
// create client
elasticClient = new PreBuiltTransportClient(settings);
// add hosts
for (String elasticHost : config.getHosts()) {
elasticClient.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));
}
} catch (UnknownHostException e) {
throw new RuntimeException("Unable to initialize Eleasticsearch client " + e.getLocalizedMessage());
}
}
示例5: ElasticVdcDAO
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public ElasticVdcDAO(ElasticDAOConfig config) {
try {
Builder builder = Settings.builder();
// Check for new hosts within the cluster
builder.put(CLIENT_SNIFFING_CONFIG, true);
// specify cluster name
if (config.getClusterName() != null) {
builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
}
Settings settings = builder.build();
// create client
elasticClient = new PreBuiltTransportClient(settings);
// add hosts
for (String elasticHost : config.getHosts()) {
elasticClient.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));
}
} catch (UnknownHostException e) {
throw new RuntimeException("Unable to initialize Eleasticsearch client " + e.getLocalizedMessage());
}
}
示例6: testPositionIncrementSetting
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public void testPositionIncrementSetting() throws IOException {
Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop")
.put("index.analysis.filter.my_stop.enable_position_increments", false);
if (random().nextBoolean()) {
builder.put("index.analysis.filter.my_stop.version", "5.0");
}
builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
Settings settings = builder.build();
try {
AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("enable_position_increments is not supported anymore"));
}
}
示例7: createClient
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
/**
* This method will create the client instance for elastic search.
* @param clusterName String
* @param host List<String>
* @param port List<Integer>
* @return boolean
* @throws Exception
*/
private static boolean createClient(String clusterName, List<String> host, List<Integer> port) throws Exception {
Builder builder = Settings.builder();
if (clusterName != null && !"".equals(clusterName)) {
builder = builder.put("cluster.name", clusterName);
}
builder = builder.put("client.transport.sniff", true);
builder = builder.put("client.transport.ignore_cluster_name", true);
client = new PreBuiltTransportClient(builder.build());
for (int i = 0; i < host.size(); i++) {
client.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(host.get(i)), ports.get(i)));
}
return true;
}
示例8: ElasticBillingDAO
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public ElasticBillingDAO(ElasticDAOConfig config) {
try {
Builder builder = Settings.builder();
// Check for new hosts within the cluster
builder.put(CLIENT_SNIFFING_CONFIG, true);
// specify cluster name
if( config.getClusterName() != null ) {
builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
}
Settings settings = builder.build();
// create client
elasticClient = new PreBuiltTransportClient(settings);
// add hosts
for( String elasticHost : config.getHosts()) {
elasticClient.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));
}
} catch (UnknownHostException e) {
throw new RuntimeException("Unable to initialize Eleasticsearch client " + e.getLocalizedMessage() );
}
}
示例9: startElasticNode
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
private void startElasticNode() throws InterruptedException, ExecutionException, IOException {
Builder builder = Settings.builder()//
.put("node.master", true)//
.put("node.data", true)//
.put("cluster.name", CLUSTER_NAME)//
// disable automatic index creation
.put("action.auto_create_index", false)//
// disable dynamic indexing
.put("index.mapper.dynamic", false)//
// disable rebalance to avoid automatic rebalance
// when a temporary second node appears
.put("cluster.routing.rebalance.enable", "none")//
.put("http.enabled", //
config.isElasticHttpEnabled())//
.put("network.host", //
config.elasticNetworkHost())//
.put("path.home", //
config.homePath().toAbsolutePath().toString())
.put("path.data", //
config.elasticDataPath().toAbsolutePath().toString());
if (config.snapshotsPath().isPresent())
builder.put("path.repo", //
config.snapshotsPath().get().toAbsolutePath().toString());
elasticNode = new ElasticNode(builder.build(), //
DeleteByQueryPlugin.class, //
CloudAwsPlugin.class);
elasticNode.start();
setElasticClient(elasticNode.client());
// wait for cluster to fully initialize and turn asynchronously from
// RED status to GREEN before to initialize anything else
// wait for 60 seconds maximum
elastic.ensureAllIndicesGreen();
}
示例10: getRandomNodeSettings
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
private Settings getRandomNodeSettings(long seed) {
Random random = new Random(seed);
Builder builder = Settings.builder();
builder.put(Transport.TRANSPORT_TCP_COMPRESS.getKey(), rarely(random));
if (random.nextBoolean()) {
builder.put("cache.recycler.page.type", RandomPicks.randomFrom(random, PageCacheRecycler.Type.values()));
}
if (random.nextInt(10) == 0) { // 10% of the nodes have a very frequent check interval
builder.put(SearchService.KEEPALIVE_INTERVAL_SETTING.getKey(), TimeValue.timeValueMillis(10 + random.nextInt(2000)).getStringRep());
} else if (random.nextInt(10) != 0) { // 90% of the time - 10% of the time we don't set anything
builder.put(SearchService.KEEPALIVE_INTERVAL_SETTING.getKey(), TimeValue.timeValueSeconds(10 + random.nextInt(5 * 60)).getStringRep());
}
if (random.nextBoolean()) { // sometimes set a
builder.put(SearchService.DEFAULT_KEEPALIVE_SETTING.getKey(), TimeValue.timeValueSeconds(100 + random.nextInt(5 * 60)).getStringRep());
}
builder.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1 + random.nextInt(3));
if (random.nextBoolean()) {
if (random.nextBoolean()) {
builder.put("indices.fielddata.cache.size", 1 + random.nextInt(1000), ByteSizeUnit.MB);
}
}
// randomize tcp settings
if (random.nextBoolean()) {
builder.put(TcpTransport.CONNECTIONS_PER_NODE_RECOVERY.getKey(), random.nextInt(2) + 1);
builder.put(TcpTransport.CONNECTIONS_PER_NODE_BULK.getKey(), random.nextInt(3) + 1);
builder.put(TcpTransport.CONNECTIONS_PER_NODE_REG.getKey(), random.nextInt(6) + 1);
}
if (random.nextBoolean()) {
builder.put(MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING.getKey(), new TimeValue(RandomNumbers.randomIntBetween(random, 10, 30), TimeUnit.SECONDS));
}
if (random.nextInt(10) == 0) {
builder.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop");
builder.put(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop");
}
if (random.nextBoolean()) {
if (random.nextInt(10) == 0) { // do something crazy slow here
builder.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 10), ByteSizeUnit.MB));
} else {
builder.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 10, 200), ByteSizeUnit.MB));
}
}
if (random.nextBoolean()) {
builder.put(TcpTransport.PING_SCHEDULE.getKey(), RandomNumbers.randomIntBetween(random, 100, 2000) + "ms");
}
if (random.nextBoolean()) {
builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getKey(), RandomNumbers.randomIntBetween(random, 0, 2000));
}
if (random.nextBoolean()) {
builder.put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getKey(), TimeValue.timeValueMillis(RandomNumbers.randomIntBetween(random, 750, 10000000)).getStringRep());
}
return builder.build();
}
示例11: main
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
Builder builder = Settings.builder();
//builder.put("client.transport.sniff", true);
builder.put("cluster.name", "elasticsearch");
Settings settings = builder.build();
String stringQuery = "{\"match_all\" : { }}";
String q = QueryParser.escape(stringQuery);
System.out.println(q);
//System.out.println(new MatchAllQueryBuilder());
Client esClient = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
QueryBuilder queryBuilder= QueryBuilders.wrapperQuery(stringQuery);
String[] fields = new String[2];
fields[0]="name";
fields[1]="name1";
SearchResponse scrollResp = esClient.prepareSearch("test")
.setTypes("test")
.setQuery(queryBuilder).setFetchSource(fields, null)
.setSize(250)//.addSort("name", SortOrder.ASC)
.get();
SearchHit[] searchHits = scrollResp.getHits().getHits();
for(SearchHit searchHit:searchHits){
System.out.println(searchHit.getSourceAsMap());
}
/*int i=0;
while (true) {
System.out.println(scrollResp);
System.out.println(scrollResp.getHits().totalHits());
//System.out.println(scrollResp.getHits().getHits().length);
//for (SearchHit hit : scrollResp.getHits().getHits()) {
//System.out.println(hit.sourceAsMap());
//System.out.println(i++);
// }
scrollResp = esClient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}*/
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
示例12: ElasticS3ObjectDAO
import org.elasticsearch.common.settings.Settings.Builder; //导入方法依赖的package包/类
public ElasticS3ObjectDAO( ElasticDAOConfig config ) {
try {
this.config = config;
Builder builder = Settings.builder();
// Check for new hosts within the cluster
builder.put(CLIENT_SNIFFING_CONFIG, true);
// specify cluster name
if( config.getClusterName() != null ) {
builder.put(CLIENT_CLUSTER_NAME_CONFIG, config.getClusterName());
}
Settings settings = builder.build();
// create client
elasticClient = new PreBuiltTransportClient(settings);
// add hosts
for( String elasticHost : config.getHosts()) {
elasticClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticHost), config.getPort()));
}
} catch (UnknownHostException e) {
throw new RuntimeException(e.getLocalizedMessage());
}
}